【问题标题】:Custom TabLayoutPanel in GWTGWT 中的自定义 TabLayoutPanel
【发布时间】:2012-07-11 11:36:26
【问题描述】:

我正在尝试创建我的自定义 TabLayoutPanel 扩展,我的代码如下:

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 如何知道要调用哪个构造函数)?

【问题讨论】:

标签: gwt uibinder gwt2


【解决方案1】:

对于您的问题:您必须将 (provided=true) 添加到小部件的 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));

    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-30
    • 2014-07-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多