kpedia
kpedia

Reputation: 217

GWT : A widget that has an existing parent widget may not be added to the detach list

This code in GWT (Sidebar is a custom that build a sidear) :

HTML html = new HTML("
                 <div id=\"container\">some stuff</div>"
        );

RootPanel.get("container").add(new Sidebar());  

... give that error :

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:136)
at com.google.gwt.user.client.ui.RootPanel.get(RootPanel.java:211)  

Can you helpplease. I have seen many explanations but nothing help me.

thanks +

Upvotes: 3

Views: 3841

Answers (1)

Thomas Broyer
Thomas Broyer

Reputation: 64541

I won't delve into explanations, as you say you read them already: enough to say this is an unsupported pattern.

In your case, you'll want to use an HTMLPanel instead of HTML widget, and use the HTMLPanel's add(Widget,String) method to put the Sidebar into the container element:

HTMLPanel html = new HTMLPanel("<div id='container'>some stuff</div>");
html.add(new Sidebar(), "container");

Upvotes: 2

Related Questions