3

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.

caarlos0
  • 20,020
  • 27
  • 85
  • 160
  • 1
    If the state for the 2nd presenter should be bookmarkable you can use `prepareFromRequest(PlaceRequest)` to handle parameters. In your 1st presenter you use `PlaceManager.revealPlace(PlaceRequest)` with a newly generated `PlaceRequest` containing the parameter. – z00bs Sep 21 '11 at 08:57

3 Answers3

5

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/.

z00bs
  • 7,518
  • 4
  • 34
  • 53
3

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);

Mikael Couzic
  • 12,283
  • 5
  • 22
  • 16
  • Agreed w/ Mikael. I have several examples in my code at https://github.com/dartmanx/mapmaker/tree/0.5.2 in the client package. I used GWT-Platform as well. – Jason Sep 21 '11 at 17:23
  • 1
    and how i do it if my other presenter is not visible yet? – caarlos0 Sep 21 '11 at 21:27
  • 1
    Haha, I didn't see it that way ! In the case the next presenter hasn't been instantiated yet, I'd just pass the ID of the car as a URL parameter (see comment of your question by z00bs), and the request the car to the server. – Mikael Couzic Sep 21 '11 at 21:39
  • 1
    haha, yea, I've not explain right my question, i just don't want to load it multiple times.. do you have another suggestion? – caarlos0 Sep 21 '11 at 21:50
  • I decide to pass the id by PlaceRequest and it worked, and, thinking about other things, like maintain the object updated, i will use this way. Well, like no one else said anything, I will vote for the only answer. Thank you mikael-couzic. – caarlos0 Sep 22 '11 at 16:54