GWT:无法按id提取html元素,因为rootpanel返回null
我是GWT的新手。我们使用的是GWT2.4.0、JDK1.6、MVP4G1.4.0 我正在尝试构建一个web应用程序,而我必须在视图中嵌入一些html代码,然后从视图中提取特定的by id,在该html中添加或删除元素或小部件。 我的html代码嵌入得很好,但提取元素不起作用 这是我的HTML文件,看起来像:GWT:无法按id提取html元素,因为rootpanel返回null,gwt,mvp4g,Gwt,Mvp4g,我是GWT的新手。我们使用的是GWT2.4.0、JDK1.6、MVP4G1.4.0 我正在尝试构建一个web应用程序,而我必须在视图中嵌入一些html代码,然后从视图中提取特定的by id,在该html中添加或删除元素或小部件。 我的html代码嵌入得很好,但提取元素不起作用 这是我的HTML文件,看起来像: <table align="center" border="1" cellpadding="1" cellspacing="10" id="transaction_monitor"
<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>
此部分工作正常,并按预期创建视图。使用F12,我可以在浏览器页面源代码中找到div id=“clientContainer”部分
但在此之后,我试图通过id“clientContainer”从html中获取“div”元素,并将标签添加到其中,如下所示:
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>
谁能告诉我我错过了什么
提前感谢。我发现我的flexTableLayout尚未连接到根面板。现在质疑这一点还为时过早
<?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>