From the documentation and source code of GWT, it seems that this class has only UIBinder functionality, and none of the base GWT widgets use this class. The main and only function of LazyDomElement is deferred access to your widget fields. Say you have a widget with a template:
<gwt:HTMLPanel> <div ui:field="lazyField" /> <div ui:field="generalField" /> </gwt:HTMLPanel>
and the Java class for it:
public class MyCoolWidget extends UIObject { interface MyUiBinder extends UiBinder<DivElement, MyCoolWidget> {} private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class); @UiField LazyDomElement<DivElement> lazyField; @UiField DivElement generalField;
So, the reason for using it depends only on the specific case of your application, you need lazy loading of the elements of your widget or not.
UPD I must say that I have not used this class in real projects :). I can imagine some kind of scenario. For example, you need to create a ticket booking panel. With the following initial requirements:
- If you need to reserve tickets for N travelers
- The input forms for each traveler are equal and quite heavy (rich html, many input fields).
So, you need to display up to 10 identical rich forms at a time, without having to access their fields before the page loads. We could build a ReservationForm widget ( ReservationForm.ui.xml with markup and ReservationForm.java for some logic) and use LazyDomElement for input fields to save our first load time.
source share