With GWT, is there a way to not load widgets declared in uibinder xml files?

One common design that I have with GWT is to create a widget that contains two children: A and B.

I declare these two widgets A and B in the uibinder file associated with my main widgets.

What I want to do is load or not widget A depending on the if statement.

The ideal approach is to set the provided = true for widget A and set widget A to null when I want to not load this widget. But GWT gives an error.

Is there a way to declare widgets in uibinder and then not load them?

thank

EDIT: After much discussion, the ideal approach is to declare the fields "provided = true" and "optional = true", when optional = true, createAndBindUI should not throw an exception if the field is null. This is a clean approach.

If you think this feature should exist in GWT, please click this issue: http://code.google.com/p/google-web-toolkit/issues/detail?id=5699

EDIT 2: using LazyPanel as described by Thomas seems to be the best way to handle this.

+3
source share
3 answers

I came across a GWT problem that brought me here, so here I will take it in 20 months.

LazyPanel visible="false", , ( setVisible(true), , .

LazyPanel UiBinder, UiBinder, SimplePanel, LazyPanel. . https://developers.google.com/web-toolkit/doc/2.4/DevGuideUiBinder#Lazy

+5

. ,

widget.removeFromParent();

, , UIBinder .

+1

XML- UiBinder, (.. ) ui.xml, , .

MVP .

EDIT:

Until your request is implemented by the GWT developers, you can extend FlowPaneland overwrite the method add(Widget)to check nullhow:

public class ExtendedFlowPanel extends FlowPanel {

    public ExtendedFlowPanel() {
        super();
    }

    @Override
    public void add(Widget w) {
        if (w != null) {
            super.add(w);
        }
    }
}

This way you can use provided = trueand transfer nullto the panel.

+1
source

Source: https://habr.com/ru/post/1777926/


All Articles