UiBinder custom widget with parameterized constructor

Fotinopoulos Giorgos picture Fotinopoulos Giorgos · Jul 20, 2011 · Viewed 11.5k times · Source

Let's say we have a custom widget that was declared using UiBinder and it needs to have some arguments in its constructor. How can I make it in order to be able to supply these arguments when i declare it in ui.xml?

That is i have a

CustomWidget(int param1, int param2)

and when i add it to a ui.xml i need to be able to do:

...

xmlns:my="urn:import:...">

<g:Container>
 <my:CustomWidget param1="1" param2="arg2"/>
</g:Container>

Answer

Peter Knego picture Peter Knego · Jul 20, 2011

Use @UiConstructor on your constructor:

@UiConstructor
CustomWidget(int param1, int param2)

Look at docs: http://code.google.com/webtoolkit/doc/latest/DevGuideUiBinder.html#Using_a_widget