gwt自定义小部件包装方法

时间:2011-01-16 15:43:28

标签: java javascript gwt

我的自定义小部件如下所示

public class CustomWidget extends Composite {

    public static CustomWidget wrap(com.google.gwt.dom.client.Element element) {

        assert Document.get().getBody().isOrHasChild(element);

        CustomWidget customWiget = new CustomWidget(element);//this line is still ok,customWidget has value

       customWiget.onAttach();//i get Caused by: java.lang.NullPointerException: null 
       RootPanel.detachOnWindowClose(customWiget);


        return button;
      }


protected CustomWidget(com.google.gwt.dom.client.Element element) {
        setElement(element);


}

}

是我正确编写的wrap方法吗?我在评论的那一点上得到了错误

Element element = DOM.getElementById( object );
CustomWidget testKeyValue= CustomWidget.wrap(element);

1 个答案:

答案 0 :(得分:0)

请在此行之后检查element != null

Element element = DOM.getElementById( object );

(可能断言是turned off,所以你当前的代码只会在onAttach()中失败。)