2

A rookie here.

I just started with Ray Ryan's Google IO talk and following some articles on Google Developers site. I have not used any of the GWT add-ons like GWTP or MVP4G or GIN or any other stuff. Just followed the contacts example on the GWT site and tried to model my case.

I have a DockLayout panel which has a header, a navigation tree on the left and a central main panel. All of this i have in a single DefaultView which implements DefaultPresenter .

Now i have a DialogBox which pops up when the user does something in the tree and this is modelled in DialogView and DialogPresenter respectively.

Now when i hide the DialogBox , i am ending up calling a new instance of DefaultPresenter from the AppController which by virtue creates a new DefaultView and all of my tree selections and other changes in the main central panel are gone.

  1. Is it possible to re use instances of presenters without creating a new one on history change ? (for eg, DefaultPresenter in my case)
  2. Is there a way in MVP pattern to pass controls between presenters with values persisting ?
  3. How to load a existing instance of a presenter inside app controller on an event fire ?

Or have i got the whole MVP architecture thing wrong ? I am now planning to have different presenters and views for each of my components say HeaderPresenter / HeaderView, TreePresenter / TreeView , MainContentPresenter/MainContentView ?So that i will only create new instances of presenters which i need (like MainContentPresenter ) and keep the existing ones as it is (like TreePresenter and HeaderPresenter) Does this solve my problem ? How would i stitch all of this different views in the browser window ? I am not using UiBInder , just sticking to basics .

Help me out all you experts, i am in a deadlock !

Napster
  • 157
  • 3
  • 17

1 Answers1

2

When I read your question it felt like the answer should be an article, something along the lines of Stateful Presenter Architecture for GWT Apps. This is StackOverflow, however, which is all about conciseness, so let's see:

Answers

1. Is it possible to re use instances of presenters without creating a new one on history change?

Definitely. Nothing prevents you from switching between a bunch of singleton presenters injected with your views (the switching will happen in your implementation of ActivityMapper). Note the assumption from hereafter that your presenters are Activities.

2. Is there a way in MVP pattern to pass controls between presenters with values persisting ?

Since your presenters are now singletons they'll retain the state of their member variables. For message exchange between presenters, events and EventBus are your friends.

3. How to load a existing instance of a presenter inside app controller on an event fire ?

Your ActivityMapper instance, once registered with your ActivityManager, should suffice. The ActivityManager will rely on your implementation of public Activity getActivity(Place place) of the ActivityMapper interface to return one of your singleton presenters.

Resources

David Chandler's Google I/O 2011 GWT session touches on exactly this type of master/details architecture. I highly recommend it in general and for this question specifically the part following the 18th minute, when David begins a thorough overview of Activities and Places.

ftr
  • 2,105
  • 16
  • 29
Boris Brudnoy
  • 2,405
  • 18
  • 28