In order to reduce some duplicated codes/class, I tried to use several XML templates for only 1 owner class. The official GWT guide has pointed out how to do this.
public class FooPickerDisplay extends Composite{
@UiTemplate("RedFooPicker.ui.xml")
interface RedBinder extends UiBinder<Widget, FooPickerDisplay> {}
private static RedBinder redBinder = GWT.create(RedBinder.class);
@UiTemplate("BlueFooPicker.ui.xml")
interface BlueBinder extends UiBinder<Widget, FooPickerDisplay> {}
private static BlueBinder blueBinder = GWT.create(BlueBinder.class);
@UiField Button button1;
}
The '@UiField' will cause compile error, it said "Field button1 has no corresponding field in template file BlueFooPicker.ui.xml"
My RedFooPicker.ui.xml and BlueFooPicker.ui.xml have totally different contents, so there is UiField="button1" in RedFooPicker.ui.xml but no button1 in BlueFooPicker.ui.xml.
So my question is that, if there is any way that I can use multiple XML templates with totally different contents for the same owner class without causing this kind of error?
No, each UiBinder
must act on a distinct owner class. You can however easily create an inner class for one of the UiBinder
. The example in the doc is about using one or the other, not both at the same time.
BTW, to reduce duplication, you'd better try to abstract things into reusable widgets.