Search code examples
gwtuibinderdialoggwtp

why can't i hide DialogBox in UiBinder in GWT?


in Test.ui.xml

<g:DialogBox ui:field="wishlistDialogBox" autoHide="true">
     <g:caption>Test</g:caption>
     <g:HTMLPanel> some widgets..</g:HTMLPanel>
</g:DialogBox>

After running, the application still show the DialogBox, so I tried to set hide for "wishlistDialogBox" in TestView.java but it didn't work.

  @UiField DialogBox wishlistDialogBox;
  @Inject
  public TestView(final Binder binder) {
        widget = binder.createAndBindUi(this);
        wishlistDialogBox.hide();
   }

Then i set hide for it in TestPresenter.java but it still didn't work

  @Override
  protected void onBind() {
      super.onBind();
      getView().getWishlistDialogBox().hide();
  }

What's wrong, Goodle didn't explain it at all.

In addition, how to reuse the DialogBox?


Solution

  • DialogBox (and PopupPanels in general) does not work like any other widget when speaking about adding them to the DOM. You should never attach them directly to it (i.e., panel.add(yourDialogBox) or inside a UiBinder XML file) as you did. Instead you should create them, and simply call hide()/show(), and the like methods, to get it displayed/hidden (i.e., attached/detached at the end of/from the DOM).