2012-07-11 55 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的