如何从GWT DockLayoutPanel获取Id的元素?

时间:2014-07-28 08:28:45

标签: java gwt layout web docklayoutpanel

我是GWT和Java的新手。

我尝试用GWT创建一个DockLayoutPanel,并从中创建UI元素。

但它失败了,我收到了错误消息:

  

[ERROR] [MainPage] - 无法加载模块入口点类com.Test.MainPage(有关详细信息,请参阅相关的异常)

java.lang.AssertionError:具有现有父窗口小部件的窗口小部件可能无法添加到分离列表中     在com.google.gwt.user.client.ui.RootPanel.detachOnWindowClose(RootPanel.java:138)

MyDockLayoutPanel.ui.xml中的一些内容

 <g:DockLayoutPanel unit='EM'>
   <g:north size='5'>
     <g:FlowPanel styleName="{style.northPanel}">
       <g:Label>This is the NORTH panel</g:Label>
     </g:FlowPanel>
   </g:north>
   <g:west size='15'>
     <g:FlowPanel styleName="{style.westPanel}">
       <g:Label>This is the WEST panel</g:Label>
     </g:FlowPanel>
   </g:west>
   <g:center>
     <g:FlowPanel styleName="{style.centerPanel}">
       <g:Label>This is the CENTER panel</g:Label>
       <g:HTML>
        <h1>Web Application Starter Project</h1>

        <table align="center">
          <tr>
            <td colspan="2" style="font-weight:bold;">Please enter your name:</td>        
          </tr>
          <tr>
            <td id="nameFieldContainer"></td>
            <td id="sendButtonContainer"></td>
          </tr>
          <tr>
            <td colspan="2" style="color:red;" id="errorLabelContainer"></td>
          </tr>
        </table>
        </g:HTML>
     </g:FlowPanel>
   </g:center>         
 </g:DockLayoutPanel>

MainPage.java中的一些内容

public void onModuleLoad() {


    SGCDockLayoutPanel p = new SGCDockLayoutPanel();
    RootLayoutPanel.get().add(p);       

    final Button sendButton = new Button("Send");
    final TextBox nameField = new TextBox();
    nameField.setText("GWT User");
    final Label errorLabel = new Label();

    // We can add style names to widgets
    sendButton.addStyleName("sendButton");

    // Add the nameField and sendButton to the RootPanel
     Use RootPanel.get() to get the entire body element
    RootPanel.get("nameFieldContainer").add(nameField);
    RootPanel.get("sendButtonContainer").add(sendButton);
    RootPanel.get("errorLabelContainer").add(errorLabel);
}

1 个答案:

答案 0 :(得分:0)

使用HTMLPanel及其自己的特定add代替HTML窗口小部件并尝试使RootPanel正常工作(您应该看到断言失败的方式,这就是它失败的原因)