Reputation: 11
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
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:
wrap
method, but SimpleCheckBox
does.Upvotes: 2