我是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"> </td>
</tr>
<tr id="tran_body">
<td style="background-color:#CCFFFF;">
<div id="clientContainer"></div>
</td>
<td style="background-color:#CCFFFF;"> </td>
</tr>
<tr id="tran_footer" style="background-color:#CCFFFF;">
<td colspan="2"> </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>
任何人都可以指向我,我缺少的是什么?
在此先感谢。