Search code examples
javagwtuibinder

GWT project structure with UiBinder


If I have the following class com.mywebapp.client.ui.MyWidget:

public class MyWidget extends Composite {
    interface MyWidgetUiBinder extends UiBinder<Widget, MyWidget>{}
    private static MyWidgetUiBinder uiBinder = GWT.create(MyWidgetUiBinder.class);

    ...
}

And it's corresponding UiBinder:

<!-- MyWidgetUiBinder.ui.xml -->
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder' xmlns:g='urn:import:com.google.gwt.user.client.ui'>
    <!-- ... -->
</ui:UiBinder>

Then:

  1. Where (what package or folder) does MyWidgetUiBinder.ui.xml go? Does GWT allow you to make this configurable or does it require that you place it somewhere specifically?
  2. How granular should UiBinder snippets be? For every Widget? For every display region? 1 per "page"/screen?

Thanks in advance!


Solution

  • UiBinder looks for a file named after the enclosing class of the interface (if any, otherwise the interface name), in the same package as that class.

    In your case, it'll look for a com/mywebapp/client/ui/MyWidget.ui.xml.

    This is the default, and can be overridden using @UiTemplate. See https://developers.google.com/web-toolkit/doc/latest/DevGuideUiBinder#Apply_different_xml

    As for the granularity, UiBinder templates should be kept an implementation detail of a widget.