One common design I have with GWT is to create a widget which contains two children: A and B.
I declare these two widgets A and B in the uibinder file associated to my main widget.
What I want to do is to load or not widget A depending on an if statement.
Ideal approach is to set provided=true for widget A and to set widget A to null when I want to not load this widget. But GWT throws an error.
Is there a way to declare widgets in uibinder and then not loading them ?
thanks
EDIT: after a lot of discussions, an ideal approach is to declared a field "provided=true" and "optional=true" when optional=true, createAndBindUI must not throw an Exception if the field is null. This is a clean approach.
If you think that this feature must exists in GWT, please star this issue: http://code.google.com/p/google-web-toolkit/issues/detail?id=5699
EDIT 2 : using the LazyPanel as described by Thomas seems to be a better way to handle this.
I stumbled on the GWT issue, which led me here, so here's my take on it, 20 months later.
Use a LazyPanel
and set it to visible="false"
so that it's content is not built until you need it (simply call setVisible(true)
to reveal it, triggerring the lazy-initialization of its content.
LazyPanel
is fully integrated with UiBinder so that you declare its content in the same UiBinder template, as if it were a SimplePanel
, without even bothering creating a subclass of LazyPanel
. See https://developers.google.com/web-toolkit/doc/2.4/DevGuideUiBinder#Lazy