문제

I am trying to use method addHandler on a Button. Following is my code:

private void attachClickHandler(Widget widget) {
    ClickHandler clickHandler1;
    ClickHandler clickHandler2;

    clickHandler1 = new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            System.out.println("ClickHandler One");
        }

    };
    clickHandler2 = new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            System.out.println("ClickHandler Two");
        }

    };
    ((Button) widget).addClickHandler(clickHandler1);
    widget.addHandler(clickHandler2, ClickEvent.getType());
}

If I add both handlers, it works perfectly. But if I try to add only clickHandler2 (with widget.addHandler(...), then the handler is not called.

Not able to figure out why?

Thanks in advance.

도움이 되었습니까?

해결책

Only thing needed to get this working was:

Change

widget.addHandler(clickHandler2, ClickEvent.getType());

to

widget.addDomHandler(clickHandler2, ClickEvent.getType());

다른 팁

Simply add

widget.sinkEvents(Event.ONCLICK);

this registers the dom 'click' event to trigger the event

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top