passing parameters from one presenter to another w

2019-05-14 00:17发布

问题:

I'm trying to pass a parameter that I have loaded on a presenter to another presenter, a car from some client, for example.

What's the best way to do this? Using the gatekeeper? Any example?

PS: I using DI with gin and the GWT-Platform framework.

回答1:

If the presenter should be loaded when the event is fired you can use a ProxyEvent. Have a look at http://code.google.com/p/gwt-platform/wiki/GettingStarted?tm=6#Attaching_events_to_proxies and http://arcbees.wordpress.com/2010/08/31/using-proxyevent/.



回答2:

If you want to reduce coupling, you should create a custom event, CarLoadedEvent or something. Use GWTP Plugin for that, it works great. Then have your presenter that wants to catch that event implement CarLoadedHandler, and in its onBind() method, make it register to the eventBus :

@Override
protected void onBind() {
super.onBind();
registerHandler(getEventBus().addHandler(CarLoadedEvent.TYPE, this));
}

Finally, when a car is loaded, fire an event :

CarLoadedEvent.fire(getEventBus(), myLoadedCar);



回答3:

See GWTP doc & blog:

  • for regular Event handling
  • for Event handling that should wake up another Presenter not yet initialized/showing
  • boilerplate code generation related to simplifying coding Event handling