Je cherche à créer une application Google Web Toolkit (GWT) qui utilise aussi Google Gears, mais chaque fois que j'essaie de retirer le panneau, je reçois une exception et le panneau reste là.Retirez un panneau généré en GWT après clique sur un bouton
Voici un extrait de l'exception que je reçois (je n'ai inclus les bits correspondants de la pile d'appel, le reste descend juste dans la fonction incluse ci-dessous):
java.lang.AssertionError: A widget that has an existing parent widget may not be added to the detach list
at com.google.gwt.user.client.ui.RootPanel.detachOnWindowClose(RootPanel.java:122)
at com.google.gwt.user.client.ui.RootPanel.get(RootPanel.java:197)
Je ne suis pas sûr quel est le problème, mais je n'aime vraiment pas laisser le bouton là après avoir approuvé l'utilisation de Gears.
Qu'est-ce que je fais mal? Ou des suggestions d'une manière différente je pourrais faire ceci pour le faire fonctionner?
if(!gearsFactory.hasPermission()) {
HorizontalPanel rightPanel = new HorizontalPanel();
rightPanel.getElement().setId("gearsPrompt");
rightPanel.setVerticalAlignment(HorizontalPanel.ALIGN_MIDDLE);
rightPanel.setSpacing(0);
rightPanel.setHeight("28px");
InlineLabel enableGearsText = new InlineLabel("Enable Gears for off-line access");
enableGearsText.getElement().setId("gearsText");
enableGearsText.addStyleName("titleElement");
rightPanel.add(enableGearsText);
final Button gearsButton = new Button("Use Gears");
gearsButton.getElement().setId("gearsButton");
gearsButton.addStyleName("titleElement");
gearsButton.setHeight("24px");
gearsButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
Factory gearsFactory = Factory.getInstance();
if(gearsFactory != null) {
if(gearsFactory.getPermission()) {
RootPanel gearsPrompt = RootPanel.get("gearsPrompt");
gearsPrompt.removeFromParent();
}
}
}
});
rightPanel.add(gearsButton);
RootPanel titleBarRight = RootPanel.get("titleBarRight");
titleBarRight.add(rightPanel);
}
Malheureusement cela ne fonctionne pas. L'appel removeFromParent() est à l'intérieur d'un objet clickHandler anonyme et est donc pas dans la même portée que rightPanel. Merci pour cette idée! – Miquella