julien1987
julien1987

Reputation: 11

GWT Element Event handling

How do I attach a simple click handler to a DOM element in GWT?

@UIField com.google.gwt.dom.client.AnchorElement anchor;

How would I create an onclick handler for 'anchor' ?

Upvotes: 1

Views: 661

Answers (1)

pb2q
pb2q

Reputation: 59637

If you want to use the ClickHandler interface, you can do this by wrapping the AnchorElement with an Anchor, which has an addClickHandler method and a wrap method.

So, for instance:

AnchorElement myAnchor;
Anchor anchorWrapper = Anchor.wrap(myAnchor);
anchorWrapper.addClickHandler(myClickHandler);

will do the trick.

This generally works for many of the UI elements:

But the wrap method is not an inherit from Widget, so there are some exceptions:

Upvotes: 2

Related Questions