0

In GWT app where one has multiple presenters rendering views based on user actions/events, I have certain questions wrt MVP

1) What is the best way to pass data between multiple presenters. For example one presenter needs to pass a String or any other Object to other presenter. Of course the method should be such that presenters are still decoupled

2) For navigation around multiple presenters/views should one use Events or History or Both? Is there any specific drawback of using only History tokens and not having events

kapandron
  • 3,546
  • 2
  • 25
  • 38
Vishal Biyani
  • 4,297
  • 28
  • 55

2 Answers2

3

Passing complex information between presenters is done best via events.
However I wouldn't completely neglect History. If you want to support bookmarks and allow the user to load/go back to a specific application state/view you have to use History.

You might use a hybrid approach between Activity/Places and Custom Events.

  • Parse the history token (Activity/Places)
  • Load the application state/information based on the history token
  • Use events to update the various presenters/views
Ümit
  • 17,379
  • 7
  • 55
  • 74
1

MVC is not really simple to use with GWT. The best practice for GWT is the MVP model. There is a very good presentation from Google I/O 2009 at google-code.

And there is a really good tutorial for MVP with GWT.

The difference between MVP and MVC is explained very detailed here at stackoverflow.com.

Sorry not to answer your question directly - but I think your problem comes by using an unfitting design-pattern. IMHO with the MVP-pattern the question will be solved.

Community
  • 1
  • 1
Erik
  • 3,777
  • 21
  • 27
  • Oops..I meant to type MVP, but some background lens made me write MVC. so I am using exactly same design pattern as suggested in your article and it's working very well. The only difficulty I am having is in passing data between presenters, and only that part is clumsy. Rest I got quite clean! – Vishal Biyani Dec 14 '11 at 07:50
  • After going through article again today, I feel I made a wrong choice when I banked on History instead of events. Events carry the data very well, I probably didn't realize their usefulness in beginning, but now I can see it! – Vishal Biyani Dec 14 '11 at 07:53
  • 1
    Best practice is passing Objects instead of Strings. Events usually carry any Object. If you use History only, you need to pass everything as String. IMHO this definitifly is a very "expensive" (means: a lot of work) and unstable way to handle your internal communication. – Erik Dec 14 '11 at 07:56