Search code examples
eventsnestedgwtppresenter

GWTP : events and nested presenters


I have some problems with events in GWTP.

I have a MainPresenter which extends TabContainerPresenter. This presenter is linked to a MainView which contains some ui components + some com.gwtplatform.mvp.client.Tab : HomeTab, ContactTab and so on.

MainPresenter is supposed to react to some events "MyEvent" MyEvent has a corresponding MyHandler and has been created following those good practices http://arcbees.wordpress.com/2010/08/24/gwt-platform-event-best-practice/

When I fire an event from a ui component of MainView like this :

MyEvent.fire(this, new MyEventContext(..));

I correctly catch the event in MainPresenter.

But When I do exactly the same in one of the "Tab Presenter", the event is not caught by the MainPresenter.

For example, in HomePresenter which is the "HomeTab" of MainPresenter, when I do

MyEvent.fire(this, new MyEventContext(..));

I can catch the event from the HomePresenter but not from the MainPresenter.

Any idea?


Solution

  • Make sure you respect those rules:

    1. The EventBus you inject in your View is com.google.web.bindery.event.shared.EventBus (and not com.google.gwt.event.shared.EventBus)
    2. In the Presenter that handles the event (HomePresenter or MainPresenter), register to the event using the addRegisteredHandler method, inside the onBind lifecyle method:

      @Override
      protected void onBind() {
          super.onBind();
      
          addRegisteredHandler(MyEvent.getType(), this);
      }
      

    I don't know what is your particular mistake that you've done. To help you, I made a quick proof of concept which shows that events can be sent from a tabbed presenter to a TabContainerPresenter. Clone this project, and head to the #!settingsPage. You'll see two "Fire true" and "Fire false" buttons, which will fire events that will be caught by the ApplicationPresenter.