2011-03-07 50 views
1

我想實現一個自定義的TabLayoutPanel,當添加一個窗口小部件(通過自定義動作,如關閉標籤等)時,它會自動設置標籤本身。帶參數的GWT UiConstructor,類沒有適當的setter方法

我創建了一個CustomTabPanel.ui.xml以及一個CustomTabPanel.java。 UI設計只是嵌入一個TabLayoutPanel,代碼部分公開了我需要的一些功能。 我也有一個構造函數,它採用與TabLayoutPanel相同的兩個參數,我想在UI設計模式中傳遞,就像我對普通的TabLayoutPanel所做的一樣。 它看起來像這樣

public class CustomTabPanel extends Composite{ 
    /* ... here all the uiBinder things 
     already written by my eclipse plugin */ 

    @UiField(provided=true) 
    TabLayoutPanel tabPanel; 

    public @UiConstructor CustomTabPanel(double barHeight, Unit barUnit){ 
     tabPanel = new TabLayoutPanl(barHeight, barUnit); 
     initWidget(uiBinder.creatAndBindUi(this)); 
    } 

我使用自定義組合構件在另一個.ui.xml文件 但是,當我啓動,並在我的瀏覽器中測試Web應用程序,我得到以下錯誤:

Class CustomTabPanel has no appropriate setBarUnit() method. Element <my:ClosableTabPanel barHeight='2' barUnit='EM' ui:field='closablepanel'>

我按照http://code.google.com/intl/fr/webtoolkit/doc/latest/DevGuideUiBinder.html#Using_a_widget上的說明進行操作。我想我已經錯過了一些東西,但是我不知道它是什麼。

此外,我嘗試通過創建派生的class ExtendedTabLayoutPanel extends TabLayoutPanel{...}並使用參數實現構造函數來使用繼承。這給了我,在運行時,另一個錯誤:

Line xx: Type mismatch: cannot convert from TabLayoutPanel to ExtendedTabLayoutPanel

希望我很清楚......很快就讀到您!

回答

4

我遇到了同樣的問題。事實證明,論點的順序很重要,請參閱http://code.google.com/p/google-web-toolkit/issues/detail?id=5272

如果您擁有訂單權限,則無需擔心轉換枚舉。我現在有這樣的:

public @UiConstructor FancyTabLayoutPanel(Unit barUnit, double barHeight) {...} 

...在我.ui.xml文件:

<v:FancyTabLayoutPanel barUnit="EM" barHeight="2.0"></v:FancyTabLayoutPanel> 

不知的參數要求的順序在不同的部署是強健?

+0

一切工作正常,單位作爲第一個參數。 – 2011-03-08 08:22:17

0

您的問題可能與com.google.gwt.dom.client.Style.Unit是一個枚舉有關。應該解決問題的另一種方法是將barUnit更改爲字符串類型,然後使用Unit.valueOf(barUnit)來檢索適當的枚舉值。這也使您能夠正確地錯誤檢查傳遞的單元名稱。

至於在UiBinder中的繼承問題,這實際上是一個known issue已修補但尚未正式添加到GWT。

+0

即使將單位作爲字符串傳遞,錯誤仍然存​​在。雖然,它作爲單位或字符串傳遞時工作正常,但作爲第一個參數。似乎它符合z0r所說的錯誤。 – 2011-03-08 08:21:48