Reputation: 12356
I want to create a custom widget that allows to specify its nested sub-elements in UiBinder. Just like DockPanel
can have south
, north
, etc. I looked at the source code of DockPanel
but haven't found a solution.
<my:LeftRightToolbar>
<left>
<g:Button/>
</left>
<right>
<g:Button/>
</right>
</my:LeftRightToolbar>
UPDATE: Can I have multiple sub nodes under my custom <left>
and <right>
? The code doesn't compile if I add more than one widget.
Upvotes: 1
Views: 708
Reputation: 15321
First thing - <left>
and <right>
have to be in the same namespace as LeftRightToolbar
, so it should be <my:left>
and <my:right>
.
Secondly, you need to annotate two methods in LeftRightToolbar
with the @UiChild
annotation:
@UiChild(tagname = "left")
void addToLeft(Widget widget) {
left.add(widget);
}
@UiChild(tagname = "right")
void addToRight(Widget widget) {
right.add(widget);
}
The method addToLeft
will be called to add the widget specified in <my:left>
tags. The <my:right>
tag is handled by addToRight
.
If you need to add multiple widgets to your custom tags, you should put a container in them, like FlowPanel
.
Upvotes: 2