3
votes

I would like to create a custom GWT composite widget that I can later use this way in *.ui.xml using uiBinder (cw is prefix for my custom widgets package):

<cw:CustomPanel>  
  <cw:header><g:Label>test</g:Label></cw:header>  
  <cw:content><g:Label>test</g:Label></cw:content>  
</cw:CustomPanel>

In short, I would expect that setHeader and setContent methods on my custom widget are called by the framework somehow.

Is that at all possible?

2

2 Answers

2
votes

This is what @UiChild is for, see the JavaDoc at http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/uibinder/client/UiChild.html

If you want to keep the method names setHeader and setContent (instead of addHeader and addContent), you'll have to use

@UiChild(tagname = "header")
void setHeader(Widget headerWidget) {
  ...
}
0
votes

Create setHeader(String title) and setContent(String content) methods in your widget's Java class. In these methods add text to your header and content panel respectively. Then you can use this widget in Ui:Binder this way:

<cw:CustomPanel header="test" content=test" />