0

我想为我的复合表单使用基类,而不是直接从复合本身继承。当我这样做时,GWT 设计师会吐槽子类。

这是我的基类:

package com.mycompany.project.client.panels;

import com.google.gwt.user.client.ui.Composite;
import com.mycompany.project.client.PanelNotifyCallback;

public class PanelBase extends Composite
{
protected PanelNotifyCallback NextButtonNotify = null;
protected PanelBase THIS = this;

public void setNextButtonNotify( PanelNotifyCallback nextButtonNotify )
{
    NextButtonNotify = nextButtonNotify;
}
}

这是一个子类:

package com.mycompany.project.client.panels.p2;


import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.user.client.ui.DoubleBox;
import com.mycompany.project.client.panels.PanelBase;

public class Panel2 extends PanelBase
{

public Panel2()
{

    AbsolutePanel absolutePanel = new AbsolutePanel();
    initWidget(absolutePanel);
    absolutePanel.setSize("472px", "227px");

    Label lblPanel = new Label("Panel2");
    lblPanel.setStyleName("gwt-Label_Panel1");
    absolutePanel.add(lblPanel, 193, 88);
    lblPanel.setSize( "67px", "23px" );

    Button btnNext = new Button( "Next" );
    btnNext.addClickHandler( new ClickHandler()
    {
        public void onClick( ClickEvent event )
        {
        //  NextButtonNotify.Notify( THIS );
        }
    } );
    absolutePanel.add( btnNext, 196, 166 );

    Label lblPrice = new Label("Price:");
    absolutePanel.add(lblPrice, 35, 37);

    DoubleBox doubleBoxPirce = new DoubleBox();
    doubleBoxPirce.setName("PriceBox");
    absolutePanel.add(doubleBoxPirce, 75, 25);
}
}

这是我打开 panel2.java 的设计视图时发生的情况

Exception during 'super' constructor evaluation
An exception happened during evaluation of constructor PanelBase() using arguments {}. 

java.lang.AssertionError: This UIObject's element is not set; you may be missing a call to either Composite.initWidget() or UIObject.setElement()
at com.google.gwt.user.client.ui.UIObject.getElement(UIObject.java:556)
at com.mycompany.project.client.panels.PanelBase$$EnhancerByCGLIB$$9c1b2ca8.CGLIB$getElement$30(<generated>)
at com.mycompany.project.client.panels.PanelBase$$EnhancerByCGLIB$$9c1b2ca8$$FastClassByCGLIB$$1a67578f.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:215)

我可以制作自己的基类并且仍然让设计师工作吗?如果是这样,有什么问题?这是一个相当简单的设置。从长远来看,我还想创建一些抽象基类。

我可以打开基类 PanelBase 的设计器视图。

4

1 回答 1

0

我找到了原因,导致设计师窒息的原因。

受保护的 PanelBase THIS = this;

那条线。如果您在基类中复制“this”指针,那么当您尝试打开子类上的设计选项卡时,设计器会呕吐。即使您在构造函数中执行此分配,它仍然会呕吐。

我不认为有解决办法。我只是想在子类中的一些匿名类中使用“this”指针。我认为基类将是这个参考的一个很好的持有者。

于 2013-01-18T19:32:37.047 回答