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

标签 gwt

GWT中的这段代码(Sidebar是一个自定义的构建sidear的):

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

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

...给出那个错误:

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)  

你能帮忙吗?我看过很多解释,但没有任何帮助。

谢谢+

最佳答案

我不会深入解释,因为您说您已经阅读过它们:足以说明这是一种不受支持的模式。

在您的情况下,您需要使用 HTMLPanel 而不是 HTML 小部件,并使用 HTMLPanel add(Widget,String) 方法将 Sidebar 放入 container 元素中:

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

关于GWT : A widget that has an existing parent widget may not be added to the detach list,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17811050/

相关文章:

java - 如何摆脱 GWT 应用程序内部框架上的双滚动条

gwt - CSS 类定义在 <g :HTML> element 内不起作用

GWT uibinder,花费太多时间进行 self 暗示

gwt - 为什么GWT中没有isFocused()?

java - 您可以将 GWT 屏幕添加到 Web 应用程序中已有的屏幕吗?

gwt - 以 ROOT 身​​份部署在 Tomcat 中时,RPC/Servlet 无法正常工作

java - GWT:从 Java 调用 javascript 函数

java - GWT 默认请求传输 : when/why to extend?

java - 值(value)提供者路径空问题 GXT 3.0

gwt - 阐明对 Presenter 界面的理解