2012-07-11 88 views
0

我想创建我的自定义TabLayoutPanel扩展,我的代码如下:定制TabLayoutPanel在GWT

public class ExpandableTabLayoutPanel extends TabLayoutPanel { 

    @UiConstructor 
    public ExpandableTabLayoutPanel(double barHeight, Unit barUnit) { 
     super(barHeight, barUnit); 
     addExpandableBehaviour(); 
    } 

    private addExpandableBehaviour(){ 
     //... 
    } 
} 

在这里,我调用它从UiBinder的:

<a:ExpandableTabLayoutPanel barHeight="20" barUnit="PX"> 
    <a:tab> 
    <a:header>header</a:header> 
     <a:AdvancedRichTextArea styleName="{style.area}" ui:field="area"/> 
    </a:tab> 
</a:ExpandableTabLayoutPanel> 

(我是被迫的错误消息使用a:tab/a:header而不是g:tab/g:header即使我没有在我的a:程序包/工作区中定义的选项卡和标题,但这可能不是问题)

如果@UiConstructor注释存在超过ExpandableTabLayoutPanel像在上市后,我得到奇怪的错误:

[ERROR] [gwtreproduce] - <a:ExpandableTabLayoutPanel barHeight='20' barUnit='PX'> missing required attribute(s): arg1 barHeight Element <a:ExpandableTabLayoutPanel barHeight='20' barUnit='PX'> (:13) 

当我禁用@UiConstructor,我发现了更奇怪的错误:

[ERROR] [gwtreproduce] - Errors in 'generated://E6338B946DFB2D28988DA492134093C7/reproduce/client/TestView_TestViewUiBinderImpl.java' :    [ERROR] [gwtreproduce] - Line 33: Type mismatch: cannot convert from TabLayoutPanel to ExpandableTabLayoutPanel 

我在扩展TabLayoutPanel时做了什么错误?

而侧面的问题:TabLayoutPanel构造函数没有用@UiConstructor注释并且可以在UiBinder中使用(UiBinder如何知道要调用哪个构造函数)?

+0

可能重复;无法将docklayout面板转换为自定义面板](http://stackoverflow.com/questions/11433805/gwt-ui-xml-cannot-convert-docklayout-panel-to-custom-panel) – 2012-07-18 18:49:58

回答

0

对你来说问题:你必须添加(provided = true)到你的widget的UiField注解。然后在代码中,你自己,设置实例之前 createAndBindUi()调用是这样的:

class Whaoo extends Composite{ 

    /* with 'provided', UiBinder don't call any constructor */ 
    @UiField(provided = true) 
    final Great foo; 

    interface WhaooUiBinder extends 
     UiBinder<Widget, Whaoo> {} 

    private static WhaooUiBinder uiBinder = 
     GWT.create(WhaooUiBinder.class); 

    public Whaoo() { 

     // initialize "provided" before createAndBindUi call 
     foo = new Great(String bar, int pouet); 

     initWidget(uiBinder.createAndBindUi(this)); 

    } 
} 
[GWT ui.xml的
相关问题