How to replace element with my GWT widget?

后端 未结 5 521
慢半拍i
慢半拍i 2021-02-02 01:46

Is it possible to replace known html element with my widget component? (Emphasis on the word \'replace\', I don\'t want to put the widget in th

5条回答
  •  滥情空心
    2021-02-02 02:03

    It seems that calling widget.onAttach() after inserting widget into DOM does the trick.

    class MyWidget extends Composite
    {
      ...
    
      public void attach()
      {
        /* Widget.onAttach() is protected
         */
        onAttach();
    
        /* mandatory for all widgets without parent widget
         */
        RootPanel.detachOnWindowClose(this);
      }
    }
    
    tmpEl.getParentElement().replaceChild(myWidget.getElement(), tmpEl);
    myWidget.attach();
    

    Credit goes to André at Google Web Toolkit group.

    I still wonder though why there is no RootPanel.addAndReplaceElement(Widget, Element), similar to HTMLPanel.addAndReplaceElement(Widget, Element).

提交回复
热议问题