My fired event is not handled by the parent presenter

41 views
Skip to first unread message

Faissal Elamraoui

unread,
Jan 17, 2015, 4:30:55 PM1/17/15
to gwt-pl...@googlegroups.com
Hello everyone,

I have a child presenter (added to the parent in a slot) that fires an event through the eventBus (on a condition) when onBind() is called :

class ChildPresenter extends PresenterWidget<?> {
 
        void onBind() {

               instance = initMyInstance();

               if (instance == null) {
                        eventBus.fireEvent(new MyEvent());0
               }
        }
       
       //...
}

On the parent, i handle the event in the onBind() method like this :

class ParentPresenter {
        
     void onBind() {

           eventBus.addHandler(MyEvent.TYPE, new MyEventHandler() {...} );

          // I tried also this : addRegisteredHandler(LoggedOutEvent.TYPE, this) and  addVisibleHandler(...) too
         // Where i implement the MyEventHandler interface in the parent presenter
     }
}

The parent does not handle the fired event. Am i doing it wrong? I noticed also when i move the handling process to the onReveal() method of my parent presenter, it worked but twice !!


Any pointers?  Thank you.

Richard Wallis

unread,
Jan 17, 2015, 10:04:15 PM1/17/15
to gwt-pl...@googlegroups.com
Your child presenter is injected into your Parent Presenter so it must exist before your parent presenter is created.

This means that the child's onBind() runs before the parents.  So the Parent presenter has not registered its handler when the event is fired.

----

Also your code is not idiomatic.  Use addRegisteredHandler and just call fireEvent() to fire your event.

--
You received this message because you are subscribed to the Google Groups "GWTP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gwt-platform...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Faissal Elamraoui

unread,
Jan 18, 2015, 7:12:36 PM1/18/15
to gwt-pl...@googlegroups.com
Thanks Richard. It was a timing issue. To give time to the Parent to add a handler, i deferred fireEvent like this :
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
    @Override
    public void execute() {
    eventBus.fireEvent(new MyEvent());
                       }
                   });
Reply all
Reply to author
Forward
0 new messages