J'ai créé un widget en utilisant GWT uiBinder. Cela fonctionne bien, jusqu'au moment où je veux l'utiliser une deuxième fois. Après avoir appelé le constructeur une deuxième fois, il renvoie uniquement la description brute de XML et les instructions du constructeur (rootElement.add(new HTML("panel1"), leftId);
) ne fonctionnent tout simplement pas. Il ne génère aucune erreur ou avertissement.GWT: le widget basé sur uiBinder ne peut pas être instancé une deuxième fois
S'il vous plaît aider
classe 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 descriprion:
<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>
Je ne peux pas reproduire le comportement que vous décrivez. Votre widget UiBinder semble être correct. Comment ajoutez-vous le widget à un widget parent (RootPanel ou un enfant)? –
Oh, je sais ce qui pourrait être votre problème. Vos identifiants boxLeft et boxRight ne sont pas uniques si vous ajoutez le widget au DOM une seconde fois. –