Reputation: 6006
I'm learning GWT and have some questions about MVP pattern. Usually GWT app has 1 html page that is used to show module's UI. So, do we have to have 1 view class and 1 corresponding presenter class? or we should think about view as a collection of nontrivial widgets(I mean widgets that are not build in the framework, but that widgets that we write by ourselves) that is used to build complex UI on that 1 page? So in that case should we consider that complex widget as one view and write presenter for each such widget? In the latter case how the communication among all presenters can be performed? Do we need to use such approach as mediator pattern suggests or there is another technique? As we have 1 page for whole application we need smth like DialogBoxes to interact with user(in case of application that requires user to produce some data), so should we consider such DialogBox as seperate view and should it have own presenter?
However usual behavior is to have 1 page per application, are there some cases where we need to have more than 1 page and how in such case we should build our application?
Upvotes: 0
Views: 183
Reputation: 2632
If you have used MVP on other non-web frameworks , the same patterns can be applied here. Any nontrivial widget can be broken down into a view and presenter. If data persistance/communication is non trivial then you can put in a model as well.
A pattern unique to GWT is the EventBus and GWTEvents(Search for GWT Events on google). The event bus makes communication between views and presenters simple and elegant.
Upvotes: 2
Reputation: 17799
You may only have one HTML page that loads the GWT application however you will have as many pages (read "Places") that you want. A "Place" is a page that should contain a coherent unit of functionality (View list of people, dashboard, etc - sometimes you have a separate page/place for Add Thing, but you could just as easily do the add as a popup widget in the same page as List Things)
In a GWT (as I have defined my applications - others may differ), I have a Place, Activity/Presenter, and UiBinder/View for each "page". Even though these are not different HTML pages, you can configure your PlaceHistoryHandler(map url to place) and ActivityMapper (map place to activity) in a way that make the app seem like it has as many "pages" as "places" even though it is technically a single page dynamic javascript application.
Also, the Activity/Presenter+UiBinder/View+Place combo is kind of a high-level organization. You may want to create Widgets. I usually just create a UiBinder(NewThingWidget.java + NewThingWidget.ui.xml) and the NewThingWidget extends PopupPanel and takes in a callback like:
public interface NewThingCallback(){
public void onNewThing(Thing obj);
public void onCancel();
}
And then your NewThingWidget can do its thing and pass back control and possibly a new Thing when it is done.
Your higher level Activity/View/Place combo can use the widgets and widgets can be shared.
I would recommend looking a full app tutorials that have multiple "places"
Upvotes: 2