UiBinder will only ever use a single constructor for a given widget: either its zero-arg constructor, or a @UiConstructor
(I'm surprised that you say it works when using either one or the other call but not both: one should fail in every case, and one should succeed in every case; if you haven't annotated a constructor with @UiConstructor
, then <my:CustomWid/>
should always work and <my:CustomWid a="str1" b="str2"/>
should always fail)
There are two solutions here:
- use setters for the
a
andb
attributes (void setA(String a)
andvoid setB(String b)
)), and possibly check later (say, inonLoad
oronAttach
) that you have either none or both of A and B, but not one without the other (if that's your rule). - use
@UiField(provided = true)
when you need to use the other constructor (if you choose to have UiBinder use the zero-arg constructor –i.e. no@UiConstructor
–, then that means you'll have to move thea="str1" b="str2"
from the XML to the Java code:@UiField(provided = true) CustomWid myCustomWid = new CustomWid("str1", "str2")
).
The first option has my preference.