Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implement ClickHandler in custom Widget

Tags:

gwt

I am creating a custom widget in GWT extending Composite and implementing ClickHandler. I have already implemented the method onClick, but the clickEvent does not work. What method should I additionally implement in the class in order the clickEvent to work? May be HandlerRegistration? How?

like image 572
arjacsoh Avatar asked Apr 10 '12 13:04

arjacsoh


2 Answers

If you want your widget to behave like clickable GWT widgets you should use com.google.gwt.event.dom.client.HasClickHandlers interface.

public class MyWidget extends Widget
implements HasClickHandlers
{
    public HandlerRegistration addClickHandler(
        ClickHandler handler)
    {
        return addDomHandler(handler, ClickEvent.getType());
    }
}
like image 117
cardamo Avatar answered Oct 19 '22 02:10

cardamo


Try

this.addClickHandler( myClckHandler ) ;

or if not available

this.addDomHandler( myClckHandler , ClickEvent.getType()) ;

this should works

edit==> this should works:

public class Foo extends Composite {

private ClickHandler myClkHandler = new ClickHandler() {
    @Override
    public void onClick(ClickEvent event) {
        Window.alert("Overnuts is the best !") ;
    }
};

public Foo() {
    initWidget(this) ;
    this.addDomHandler( myClkHandler, ClickEvent.getType()) ;
   }
}
like image 23
Overnuts Avatar answered Oct 19 '22 02:10

Overnuts