2010-01-08 23 views
6

Tôi muốn lập trình một widget theo chương trình. Tôi có thể sao chép Element bên trong Widget với Dom.clone nhưng dường như tôi không thể tạo ra một Widget từ phần tử nhân bản này. Điều này có thể không?GWT Sao chép một tiện ích bằng cách sử dụng DOM.clone

 //somewhere in onModuleLoad()...   
    Button button = new Button("Original"); 
    RootPanel.get().add(button); 

    //.....later on... 
    Element buttonCloneElement = DOM.clone(button.getElement(), true); 
    Widget buttonClone; 

    buttonClone = new Button(buttonCloneElement); //FAIL - No such constructor 
    buttonClone.setElement(buttonCloneElement); //FAIL - No such setter method 

    //This may work but looks messy to me 
    buttonClone.getElement().setInnerHTML(button.getElement().getInnerHTML()); 

    //add the clone to the root panel?? 
    RootPanel.get().add(buttonClone); 

Có cách nào khác để nhân bản Widget không?

Trả lời

9

buttonClone = Button.wrap(buttonCloneElement)

+1

Tôi đoán tôi cần phải học cách tìm kiếm Javadoc tốt hơn:/ –

+0

Tôi có hai widget ListBox qua ** UiBinder ** * @ UiField ListBox lstHeaderSort; @UiField ListBox lstFooterSort; ** và tôi chuyển đổi thành ** lstFooterSort = ListBox.wrap (DOM.clone (lstHeaderSort.getElement(), true)); * nhưng tôi có ngoại lệ con trỏ null. Tại sao ? – Cataclysm

Các vấn đề liên quan