Search code examples
xmlgwtlayoutconstructoruibinder

GWT UiConstructor with arguments, class has no appropriate setter method


I'd like to implement a custom TabLayoutPanel which would automatically setup the tab itself when adding a widget (with custom actions such as closing the tab, etc).

I created a CustomTabPanel.ui.xml along with a CustomTabPanel.java. The UI design simply embeds a TabLayoutPanel and the code part exposes some functions that I need. I also have a constructor that takes the same 2 arguments as the TabLayoutPanel, that I would like to pass in UI design mode just as I do with the plain TabLayoutPanel. It looks like this

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));
    }

I use the custom composite widget in another .ui.xml file But then, when I launch and test the web app in my browser, I get the following error:

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

I followed the instructions read on http://code.google.com/intl/fr/webtoolkit/doc/latest/DevGuideUiBinder.html#Using_a_widget to make this. I think I have missed something but I can't find out what it is.

Also I tried before to use inheritance by creating a derived class ExtendedTabLayoutPanel extends TabLayoutPanel{...} and implementing the constructor with the arguments. This gives me, at runtime, another error :

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

Hope I'm clear enough... Read you soon!


Solution

  • I was having the same problem. It turns out that the order of the arguments is important somehow; see http://code.google.com/p/google-web-toolkit/issues/detail?id=5272

    When you have the order right, you don't need to worry about converting the enum. I now have this:

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

    ... and in my .ui.xml file:

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

    I wonder if the required order of arguments is robust across different deployments?