tags:

views:

368

answers:

1

Is there a known order to the firing of GWT EventHandlers?

ie. If I have a class that extends ListBox and add an EventHandler from the constructor, can I be sure that this Handler will be called before another Handler which is added later on by a surrounding class?

Likewise, if a subclass takes the constructor:

Subclass() {
    super();
    addChangeHandler(new ChangeHandler() {
        // ...
    });
}

But the superclass has the same constructor which adds a ChangeHandler:

Superclass(){
    addChangeHandler(new ChangeHandler() {
        // ...
    });
}

Can we assume the order in which they will be triggered as the superclass's constructor was called and added the Handler before the subclass?

Many thanks, this has been puzzling me.

Chris.

+1  A: 

The firing does occur in the order that the handlers are added. This isn't documented in the javadoc as far as I can tell but I dove into the GWT code and the com.google.gwt.event.shared.HandlerManager.HandlerRegistry.fireEvent(GwtEvent, boolean) method eventually gets called when an event gets fired.

There are some cases where all the events are fired in reverse order but this doesn't seem to be tied to the main widgets. If you do a call hierarchy on com.google.gwt.event.shared.HandlerManager.HandlerManager(Object, boolean) you will see who calls the HandlerManager with reverse firing enabled.

Carnell
Ah, yes!com.google.gwt.event.shared.HandlerManager.HandlerRegistry.fireEvent(GwtEvent<H> event, boolean isReverseOrder)You can see it here stepping through an ArrayList of EventHandler types.Thanks for that!
Chris J