I\'m trying to declare these elements in my UiBinder XML:
UiBinder uses the ID to implement its ui:field
magic, so no you can't set it from the XML.
The way to do it is to have a Java constant with the ID and use it from both sides:
@UiField(provided = true)
final String lastNameId = Document.get().createUniqueId();
@UiField InputElement lastNameField;
…
lastNameField.setId(LAST_NAME_ID);
and in the XML:
…
Note that I haven't tested the above code with type="java.lang.String"
, I've always used
a class containing various identifiers instead (or rather, an interface with a generator)
Alternatives are:
if you can, use the alternate syntax for :
read the for=""
value from Java to use it in setId()
, that way at least you remove duplication, but you'll still have the issue that your IDs possibly won't be unique (as soon as you use your UiBinder-widget more than once)
@UiField LabelElement lastNameLabel;
@UiField InputElement lastNameField;
…
lastNameField.setIf(lastNameLabel.getHtmlFor());