GWT:异常:这个小部件的父级没有实现HasWidgets,但确实如此

时间:2013-05-08 14:38:23

标签: gwt composite

我正在尝试创建一个结构,我有一个较大的UI,我可以交换进出小部件,你可以得到更详细的区域。本质上,我正在制作顶层面板,其中包含来自其他复合材料的较小面板。现在我得到了这个例外:

    13:50:51.479 [ERROR] [managementconsole] Uncaught exception escaped

com.google.gwt.event.shared.UmbrellaException: Exception caught: This widget's parent does not implement HasWidgets
    at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:129)
    at com.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:129)
    at com.google.gwt.event.dom.client.DomEvent.fireNativeEvent(DomEvent.java:116)
    at com.google.gwt.user.client.ui.Widget.onBrowserEvent(Widget.java:177)
    at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1351)
    at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1307)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:242)
    at sun.reflect.GeneratedMethodAccessor37.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: This widget's parent does not implement HasWidgets
    at com.google.gwt.user.client.ui.Widget.removeFromParent(Widget.java:204)
    at com.google.gwt.user.client.ui.LayoutPanel.insert(LayoutPanel.java:188)
    at com.google.gwt.user.client.ui.LayoutPanel.add(LayoutPanel.java:134)
    at com.impulse.mc.client.pm.PolicyManager.Init(PolicyManager.java:58)
    at com.impulse.mc.client.ManagementConsole$1.onClick(ManagementConsole.java:83)
    at com.google.gwt.event.dom.client.ClickEvent.dispatch(ClickEvent.java:56)
    at com.google.gwt.event.dom.client.ClickEvent.dispatch(ClickEvent.java:1)
    at com.google.gwt.event.shared.GwtEvent.dispatch(GwtEvent.java:1)
    at com.google.web.bindery.event.shared.EventBus.dispatchEvent(EventBus.java:40)
    at com.google.web.bindery.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:193)
    at com.google.web.bindery.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:88)
    at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:127)
    at com.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:129)
    at com.google.gwt.event.dom.client.DomEvent.fireNativeEvent(DomEvent.java:116)
    at com.google.gwt.user.client.ui.Widget.onBrowserEvent(Widget.java:177)
    at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1351)
    at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1307)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:242)
    at sun.reflect.GeneratedMethodAccessor37.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
    at java.lang.Thread.run(Unknown Source)

我的顶级课程:

public class ManagementConsole implements EntryPoint
{
    private MCConstants constants = GWT.create(MCConstants.class);

    private final DockLayoutPanel dockLayoutPanel = new DockLayoutPanel(Unit.EM);
    private final VerticalPanel verticalPanel = new VerticalPanel();
    private final HorizontalPanel menuBar1 = new HorizontalPanel();
    public final HorizontalPanel menuBar2 = new HorizontalPanel();
    public final HorizontalPanel menuBar3 = new HorizontalPanel();
    private final Button btnPolicyManager = new Button("#Policy Manager");
    public final LayoutPanel mainPanel = new LayoutPanel();
    private final AbsolutePanel absolutePanel = new AbsolutePanel();
    private final TextArea txtrSplashScreenPut = new TextArea();
    private PolicyManager PM = null;
    private final ManagementConsole MC = this;

    /**
     * This is the entry point method.
     */
    public void onModuleLoad()
    {
        ABManager.setFactory( (MyABFactory) GWT.create( MyABFactory.class ) );
        ServerUtil.initServer();

        RootLayoutPanel root = RootLayoutPanel.get();

        root.add(dockLayoutPanel);
        root.setWidgetLeftRight(dockLayoutPanel, 0.0, Unit.PX, 0.0, Unit.PX);
        root.setWidgetTopHeight(dockLayoutPanel, 0.0, Unit.PX, 512.0, Unit.PX);
        verticalPanel.setBorderWidth(1);

        dockLayoutPanel.addNorth(verticalPanel, 7.7);
        verticalPanel.setWidth("100%");
        menuBar1.setStyleName("MenuBarStyle");
        menuBar1.setBorderWidth(1);

        verticalPanel.add(menuBar1);
        menuBar1.setWidth("0px");
        menuBar1.setSpacing( 10 );

        btnPolicyManager.addClickHandler( new ClickHandler()
        {
            public void onClick( ClickEvent event )
            {
                if ( null == PM )
                {
                    PM = new PolicyManager();
                }

                PM.Init( MC );
            }
        } );
        btnPolicyManager.setText( constants.policyManagerButton() );

        menuBar1.add( btnPolicyManager );

        verticalPanel.add( menuBar2);
        menuBar2.setWidth("0px");


        verticalPanel.add(menuBar3);
        menuBar3.setWidth("0px");

        dockLayoutPanel.add(mainPanel);

        mainPanel.add(absolutePanel);
        mainPanel.setWidgetLeftWidth(absolutePanel, 276.0, Unit.PX, 383.0, Unit.PX);
        mainPanel.setWidgetTopHeight(absolutePanel, 95.0, Unit.PX, 186.0, Unit.PX);
        txtrSplashScreenPut.setReadOnly(true);
        txtrSplashScreenPut.setTextAlignment(TextBoxBase.ALIGN_CENTER);
        txtrSplashScreenPut.setText("Splash Screen\r\nPut a graphic or some other text here");

        absolutePanel.add(txtrSplashScreenPut, 113, 57);
    }
}

在Init方法中导致异常的类:

public class PolicyManager extends Composite
{
    ManagementConsole MC = null;
    private final DockLayoutPanel myRootPanel = new DockLayoutPanel(Unit.EM);
    private final DockLayoutPanel sidePanel = new DockLayoutPanel(Unit.EM);
    private final DockLayoutPanel mainPanel = new DockLayoutPanel(Unit.EM);
    private final Label lblWelcomeToThe = new Label("Welcome to the Policy Manager");

    // Only put in basic things that do not need the MC in the constructor
    public PolicyManager()
    {

        initWidget(myRootPanel);
        setSize("961px", "412px");
        myRootPanel.setSize("100%", "412px");

        myRootPanel.addWest(sidePanel, 17.3);

        myRootPanel.add(mainPanel);

        mainPanel.add(lblWelcomeToThe);

    }

    public void Init( ManagementConsole mc )
    {
        MC = mc;
        mc.menuBar2.clear();
        mc.menuBar3.clear();
        mc.mainPanel.clear();

        // This line causes the exception
        mc.mainPanel.add( myRootPanel );


    }
}

我不明白,因为在HasWidgets中指定了clear方法。

1 个答案:

答案 0 :(得分:0)

很难跟随你的代码,因为你在不同的类中使用相同的名字,然后引用另一个类的字段..

复合的initWidget并插入dockLP(myRootPanel),然后在该子项中插入另一个dockLP。然后将myRootPanel插入LayoutPanel内部,但它已经通过initWidget添加到复合PolicyManager中。

我想如果你把它清理一下,你的堆栈跟踪可以更好地指出你的问题。看起来您的PolicyManager不需要是Composite,也不需要initWidget。只需操纵现有面板。但是,您可能会进一步清理组织。

java.lang.IllegalStateException - 如果此窗口小部件的父窗口不支持删除(例如Composite)

http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/user/client/ui/Widget.html#removeFromParent()

------------老---------

标准模式可能存在问题

LayoutPanel - “此小部件仅在标准模式下工作,这要求运行它的HTML页面具有明确的声明。”?

http://google-web-toolkit.googlecode.com/svn/javadoc/latest/index.html

如果没有,你能提供完整的追踪吗?