Pregunta

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?

¿Fue útil?

Solución

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.

Otros consejos

First, let me thank you for this awesome POC, it is an excellent basis to understand what was going wrong. I saw that I actually did not use GWTP in the good way.

The root problem was that I had 2 differents eventBus I saw it by trying

Log.info("eventBus: "+eventBus)

in the MainPresenter and in the HomePresenter. The logs showed that they did not have the same hashcode.

This was due to the fact that sometimes, I accessed directly the EventBus by doing:

EventBus.Util.getInstance();

Whereas the placeManager instantiated with:

DelayedBindRegistry.bind(GWT.create(MyInjector.class))
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top