【发布时间】:2010-05-05 08:20:03
【问题描述】:
我使用 GWT uiBinder 创建了一个小部件。它工作正常,直到我想第二次实例化它。在我第二次调用构造函数后,它只返回来自 XML 的原始描述,并且构造函数 (rootElement.add( new HTML( "panel1" ), leftId );) 中的语句不起作用。它不会引发错误或警告。
请帮忙
Java 类:
public class DashboardLayout extends Composite {
final String leftId = "boxLeft";
final String rightId = "boxRight";
interface DashboardLayoutUiBinder extends UiBinder<HTMLPanel, DashboardLayout> {
}
private static DashboardLayoutUiBinder ourUiBinder = GWT.create( DashboardLayoutUiBinder.class );
@UiField
HTMLPanel htmlPanel;
public DashboardLayout() {
HTMLPanel rootElement = ourUiBinder.createAndBindUi( this );
this.initWidget( rootElement );
rootElement.add( new HTML( "panel1" ), leftId );
rootElement.add( new HTML( "panel2" ), rightId );
}
}
XML 描述:
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'
>
<g:HTMLPanel ui:field="htmlPanel">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="40%" id="boxLeft" class="boxContextLeft">
</td>
<td width="60%" id="boxRight" class="boxContextRight">
</td>
</tr>
</table>
</g:HTMLPanel>
</ui:UiBinder>
【问题讨论】:
-
我无法重现您所描述的行为。您的 UiBinder 小部件似乎是正确的。您如何将小部件添加到父小部件(RootPanel 或子小部件)?
-
哦,我知道你可能有什么问题。如果您再次将小部件添加到 DOM,则您的 id 的 boxLeft 和 boxRight 不是唯一的。