开发者

EventHandling in GWT with LayoutPanels

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜