2010-12-12 111 views
0

我想添加一个点击处理程序到gwt html面板中定义的锚点,但没有成功。我使用下面的方法GWT添加事件处理程序到DOM元素

panel_1 = new HTMLPanel("<div class='BackHeader'>Selected Attribute:Select an Attribute to edit(<a Id='DeleteCategory'>Delete this Attribute</a>)</div>"); 
    flexTable.setWidget(3, 0, panel_1); 
Element DeleteCategory=panel_1.getElementById("DeleteCategory"); 
    Anchor C= Anchor.wrap(DeleteCategory); 

但我收到以下错误:

Exception while loading module com.BiddingSystem.client.BiddingSystem. See Development Mode for details. 
java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396) at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:183) at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:510) at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352) at java.lang.Thread.run(Thread.java:662) Caused by: java.lang.AssertionError at com.google.gwt.user.client.ui.Anchor.wrap(Anchor.java:55) at com.BiddingSystem.client.View.ProductTaxonomyView.(ProductTaxonomyView.java:174) at com.BiddingSystem.client.BiddingSystem.onModuleLoad(BiddingSystem.java:63) ... 9 more 

回答

1
Anchor a = new Anchor("hi"); 
a.addClickhandler(new ClickHandler() { 
    @Override 
    public void onClick(ClickEvent event) { 
      Window.alert("hi"); 
    } 

}); 
0

我建议你只需要使用UiBinder的......看看this tutorial。对于锚点,您将使用<g:Anchor>元素。

0

您的HTMLPanel未附加到文档。

您只能将附加元素传递给wrap()方法。

相关问题