UiBinder custom widget with parameterized constructor
Asked Answered
E

1

10

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>
Eolithic answered 20/7, 2011 at 9:36 Comment(0)
T
10

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

Terribly answered 20/7, 2011 at 11:34 Comment(2)
First of all thanks, that was the solution. But why it is not possible to add the @Uiconstructor in several constructors (overloading) ? Then how the gwt widgets offer in uibinder several arguments to pass at declaration not strictly all?Eolithic
I mean i can declare <g:VerticalPanel width="120"> and <g:VerticalPanel width="120" height="100"> but with the @UiConstructor i have to add ALL the arguments.Eolithic

© 2022 - 2024 — McMap. All rights reserved.