tags:

views:

535

answers:

3

I'm liking the new GWT2 UiBinder, however, it's not clear whether certain things are achievable using the declarative UI style.

For instance, ToggleButton only takes the image instances at construction time (no setters for up/down images). As I understand, UiBinder works in a JavaBean-like reflective way, where the assignable attributes are mapped to corresponding setters. Is this style possible with widgets like ToggleButton, where certain attributes have to be specified at construction time?

<g:ToggleButton ui:field="myBtn"></g:ToggleButton>
A: 

You can create these widgets using a @UiFactory or by providing it using @UiField(provided=true)

See http://code.google.com/webtoolkit/doc/latest/DevGuideUiBinder.html#Using%5Fa%5Fwidget

Jason Hall
Thanks for the reply, but I have to say this sucks. I ended up creating my own subclass of ToggleButton, providing the up/down image in the constructor, and in ui.xml, reference my customized widget...
EnToutCas
A: 

Try something like this:

<g:ToggleButton>
  <ui:image src="..." />
</g:ToggleButton>
Matt Moriarity
A: 

@Matt Moriarity: Thanks for the tip! I found I had to do it like this:

<g:ToggleButton ui:field="foo">
    <g:upFace><img src="images/bar.png"/></g:upFace>
</g:ToggleButton>

If you don't specify other faces (e.g. downFace), that image is used for all button states.

Edit: I guess you use ui:image when you're formally specifying external resources?

z0r