Canceling a ClickEvent

28 views
Skip to first unread message

Eugen Paraschiv

unread,
Jul 4, 2011, 6:45:34 AM7/4/11
to google-we...@googlegroups.com
I have a button with 2 ClickHandlers. After the first handler executes, I would like to cancel the event, so that it doesn't reach the second handler (based on some internal logic). Is there any way to cancel an event at this point?
I have tried: event.stopPropagation(); but it has no effect.
Any help is appreciated.
Thanks.
Eugen.

Jeffrey Chimene

unread,
Jul 4, 2011, 10:28:00 AM7/4/11
to google-we...@googlegroups.com
Were it me, it's structure this so that a single click handler fires
either one or two events. Move the decision logic into the single click
handler, and cause it to fire either one or two events. Distribute the
logic of the two current click handlers among two new event handlers.
There may be determinism issues, so synchronization logic may be required.

Eugen Paraschiv

unread,
Jul 4, 2011, 10:36:57 AM7/4/11
to google-we...@googlegroups.com
I don't have any control over the firing of the events. It's a Button and when clicked it's going to fire events to the handlers registered with it, if the event is not stopped. If it were my own logic, I could indeed control the firing logic and I could perhaps do what you suggest, but seeing how this is GWT code (and the default behavior for any entity firing events), I don't have that option.
Thanks for the feedback.
Eugen.


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


Thomas Broyer

unread,
Jul 4, 2011, 11:37:48 AM7/4/11
to google-we...@googlegroups.com
You should add a single ClickHandler that has its own logic, and the ClickHandler you'd like to be called conditionally would be known by this specific ClickHandler, which would choose whether to call or not.
Events in GWT (as in the DOM for instance) are dispatched to all handlers/listeners; even throwing an exception wouldn't stop the dispatch. If you need another behavior, you have to implement it yourself.

Eugen Paraschiv

unread,
Jul 4, 2011, 5:43:40 PM7/4/11
to google-we...@googlegroups.com
My logic was split with the purpose of decoupling two unrelated functionalities, but seeing how there is no way to do what I was trying to do, I created a custom event for one of the 2 functionalities. What could help though is to add a field to the ClickEvent, settable from the outside, so that at least data can be passed from one place to another (assuming the event object stays the same - if it doesn't then that's that).
Thanks for the help.
Eugen.

On Mon, Jul 4, 2011 at 6:37 PM, Thomas Broyer <t.br...@gmail.com> wrote:
You should add a single ClickHandler that has its own logic, and the ClickHandler you'd like to be called conditionally would be known by this specific ClickHandler, which would choose whether to call or not.
Events in GWT (as in the DOM for instance) are dispatched to all handlers/listeners; even throwing an exception wouldn't stop the dispatch. If you need another behavior, you have to implement it yourself.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
Reply all
Reply to author
Forward
0 new messages