Create your own widget and enable sub-elements in UiBinder

I want to create my own widget that allows you to specify its sub-elements in UiBinder. Just like a DockPanel can have south , north , etc. I looked at the source code of DockPanel but did not find a solution.

 <my:LeftRightToolbar> <left> <g:Button/> </left> <right> <g:Button/> </right> </my:LeftRightToolbar> 

UPDATE: Can I have several sub-settings under my custom <left> and <right> ? The code does not compile if I add multiple widgets.

+1
gwt
source share
1 answer

First: <left> and <right> must 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 using the @UiChild annotation:

 @UiChild(tagname = "left") void addToLeft(Widget widget) { left.add(widget); } @UiChild(tagname = "right") void addToRight(Widget widget) { right.add(widget); } 

To add the widget specified in the <my:left> tags, the addToLeft method is addToLeft . The <my:right> processed by addToRight .

If you need to add multiple widgets to your custom tags, you must place a container in them, such as FlowPanel .

+2
source share

All Articles