2014-10-09 43 views
0

我是GWT中的新成員。我們使用GWT 2.4.0,jdk 1.6,mvp4g 1.4.0。GWT:由於rootpanel返回null,無法通過id獲取html元素

我想構建一個Web應用程序,我必須在視圖中嵌入一些html代碼,然後必須從該視圖添加或刪除元素或小部件,在該html中選擇一個特定的id。 我的html代碼嵌入正常,但拉起元素不起作用。

這裏是我的HTML文件看起來像:

<table align="center" border="1" cellpadding="1" cellspacing="10" id="transaction_monitor" style="width:100%;border: 1px solid black;padding: 5px;"> 
    <tbody> 
     <tr id="tran_header" style="background-color:#CCFFFF;border:0px"> 
      <td colspan="2">&nbsp;</td> 
     </tr> 
     <tr id="tran_body"> 
      <td style="background-color:#CCFFFF;"> 
      <div id="clientContainer"></div> 
      </td> 
      <td style="background-color:#CCFFFF;">&nbsp;</td> 
     </tr> 
     <tr id="tran_footer" style="background-color:#CCFFFF;"> 
      <td colspan="2">&nbsp;</td> 
     </tr> 
    </tbody> 
</table> 

在視圖我已經嵌入此HTML代碼:

flexTableLayout = new FlexTable(); 

    initWidget(flexTableLayout); 

    //Window.alert(Resources.INSTANCE.synchronous().getText()); 

    HTML htmlPanel = new HTML(); 
    String html = Resources.INSTANCE.synchronous().getText(); 
    htmlPanel.setHTML(html); 

    flexTableLayout.setWidget(0, 0, htmlPanel); 

這部分工作正常,並創建視圖預期。在F12中,我可以在瀏覽器頁面源代碼中找到div id =「clientContainer」部分。

但在那之後,我試圖讓「格」從HTML的ID「clientContainer」元素,並把它添加標籤爲:

Label lblFile = new Label("File:"); 
RootPanel.get("clientContainer").add(lblFile); 

和預期這部分不能正常工作。正如我測試的那樣,我發現「RootPanel.get(」clientContainer「)」返回null。

我,甚至試圖與

Document.get().getElementById("clientContainer").add(lblFile); 

和失敗的,以及Document.get()的getElementById( 「clientContainer」)爲空。

.gwt.xml是:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.6.4//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.6.4/distro-source/core/src/gwt-module.dtd"> 
<module rename-to='onlinetoolkit'> 
    <!-- Inherit the core Web Toolkit stuff.      --> 
    <inherits name='com.google.gwt.user.User'/> 

    <!-- Inherit the default GWT style sheet. You can change  --> 
    <!-- the theme of your GWT application by uncommenting   --> 
    <!-- any one of the following lines.       --> 
    <inherits name='com.google.gwt.user.theme.standard.Standard'/> 

    <!-- Other module inherits          --> 
    <inherits name='com.mvp4g.Mvp4gModule'/> 
    <inherits name="com.google.gwt.resources.Resources" /> 

    <!-- Specify the app entry point class.       --> 
    <entry-point class='com.mvp4g.client.Mvp4gEntryPoint'/> 
</module> 

任何人都可以指向我,我缺少的是什麼?

在此先感謝。

回答

0

我覺得我的flexTableLayout還沒有附加到rootpanel。現在查詢爲時尚早。