0

我是 GWT 的新手。我们正在使用 GWT 2.4.0、jdk 1.6、mvp4g 1.4.0。

我正在尝试构建一个 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" 部分。

但在那之后,我试图通过 id "clientContainer" 从该 html 中获取 "div" 元素,并将标签添加为:

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

这部分没有按预期工作。在我测试时,我发现“RootPanel.get("clientContainer")”返回空值。

我什至尝试过

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>

谁能指出我错过了什么?

提前致谢。

4

1 回答 1

0

我发现我的 flexTableLayout 还没有连接到 rootpanel。现在查询这个还为时过早。

于 2014-10-10T20:06:22.573 回答