2

I have some questions regarding GWT (2.1) with MVP and events.

Got DockLayoutPanel with some components in it. A Tree component to the west and a SimplePanel in center. Each component has a presenter and a view. The problem is that I want to handle the components events in their presenter class, but now they are only catchable in the container which is the DockLayoutPanelPresenter . I want to handle the tree's event s in the TreePresenter. I think that the TreePresenter should handle its 'SelectedItem' events and the it can put it on the eventbus so that my other components can react to it.

Has anyone else faced this? Posted on GWT groups list, but got no reply. I think this is an imporant topic for decoupling components.

Andreas Blomqvist
  • 437
  • 1
  • 9
  • 22
  • Can you clarify your design a little more? So, you have a TreePresenter and you attached a Tree as a view to it. The view part throws an event, and you want to catch that event in the presenter? And what do you mean when you say it is only catchable in the container? – igorbel Jul 13 '10 at 22:02
  • I typed up a pretty extensive answer in this thread where I explained how I solved the dispatch in my gwt app. Maybe that can help you? http://stackoverflow.com/questions/2832779/is-there-a-recommended-way-to-use-the-observer-pattern-in-mvp-using-gwt/2832919#2832919 – Mia Clarke Nov 09 '10 at 22:08
  • Banang already gave you the best answer, imho. Use an event bus to make different parts of your UI code work with each other without having to know about each other. The only *potential* problem with the event bus is to have a very chatty application, i.e. too many events getting fired and too many handlers having to respond. Worry about that problem once you get there. – Nick Hristov Mar 13 '11 at 19:29

1 Answers1

0

In this case, where different regions of the page each have a Presenter, you could use the approach suggested by David Chandler of the GWT team:

http://groups.google.com/group/google-web-toolkit/browse_thread/thread/2812e1b15a2a98a6/8c82d629b7a48e56?lnk=gst&q=EastActivityMapper#8c82d629b7a48e56

You should read the post, but in summary, you would do something like this:

WestActivityMapper westActivityMapper = new WestActivityMapper(); 
WestActivityManager westActivityManager = new WestActivityManager(westActivityMapper, eventBus); 
westActivityManager.setDisplay(westPanel); 

EastActivityMapper EastActivityMapper = new EastActivityMapper(); 
EastActivityManager eastActivityManager = new  EastActivityManager(eastActivityMapper, eventBus); 
EastActivityManager.setDisplay(eastPanel);

dockLayoutPanel.addWest(westWidget, 50); 
dockLayoutPanel.addEast(eastWidget, 50); 
RootLayoutPanel.get().add(dockLayoutPanel); 

The west activity mapper would be responsible for displaying your Tree, and the east mapper would contain the body of your application.

We are using this approach to display a list of items in our west docked panel (not a tree, but close enough) which then updates what is displayed in the body of our app. When a user selects an item from the list we trigger a new Place event, and include the list item's id as the Place Token, so that the user can use the back button. However, you could also use the EventBus as you pointed out.

Brad Rydzewski
  • 2,523
  • 14
  • 18