Noor
Noor

Reputation: 20140

GWT add event handler to dom element

I want to add a click handler to an anchor defined in an gwt html panel with no success. I am using the following method

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);

But I am getting the following errors:

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 

Upvotes: 1

Views: 4117

Answers (3)

Sergey Savenko
Sergey Savenko

Reputation: 666

Your HTMLPanel is not attached to the document.

You can only pass attached Elements to wrap() method.

Upvotes: 0

user467871
user467871

Reputation:

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

});

Upvotes: 1

Sudhir Jonathan
Sudhir Jonathan

Reputation: 17516

I'd suggest you just use the UIBinder... take a look at this tutorial. For the anchor, you'll use the <g:Anchor> element.

Upvotes: 0

Related Questions