我想为我的复合表单使用基类,而不是直接从复合本身继承。当我这样做时,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 的设计器视图。