开发者

Cancel GWT-Event for following Handlers

I want to cancel an event for the following handlers. The sa开发者_JAVA技巧mple-class below shows, what I try. Altough the keyevent is canceled for the textbox, the second handler is still called. the order of the handlers is correct. i can prove that Handler1 is called before Handler2. in this sample-class I could use a flag, but in my real class, the handlers and the textbox are seperated, so flags would be a problem. any ideas?

public class EventTestTextBox extends TextBox {

    public static class Handler1 implements KeyUpHandler {
        @Override
        public void onKeyUp(KeyUpEvent event) {
            if (event.isShiftKeyDown()) {
                event.preventDefault();
                event.stopPropagation();
                ((TextBox)event.getSource()).cancelKey();
            }
        }
    }

    public static class Handler2 implements KeyUpHandler {
        @Override
        public void onKeyUp(KeyUpEvent event) {
            Window.alert("should not appear if shift-key is down.");
        }
    }

    public EventTestTextBox() {
        super.addKeyUpHandler(new Handler1());
        super.addKeyUpHandler(new Handler2());
    }

}


event.stopPropagation() cancels event bubbling, i.e. prevents handlers on parent elements to be triggered. It does not prevent handlers on the same element to receive the event.


I have exactly the same question as you. Did you manage to find a solution ?

I guess that the only solution would be to not register the event listener and let the handler1 dispatch (or not) to handler 2 instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜