GWT with MVP: How to communicate between 2 views? - gwt

i use the MVP-Pattern in GWT.
I have developed a GWT-TabPanel. Each Tab has his own Presenter and his own view. But now i want to use some Datas from ViewX in ViewY.
Is there a simple way to realize it?
Greetz

I would suggest to use EventBus to communicate between different views. See more about using EventBus and events in this article - Large scale application development and MVP.

Related

Integrating a GWTP project with a standard GWT project

I have a GWTP application which has no entry point because I don't ever need to run this application on its own. Rather I want to use it within a standard GWT application which has an entry point, implements its own history management mechanism, uses its own implementation of MVP framework, has its own dependency injection and so on.
The question is: Is it even possible to nicely integrate a GWTP application within a standard GWT application?
Consider this use-case for example: I want to show a popup dialog when a button is clicked in a view that is implemented in the GWT application. The popup dialog is a GWTP PresenterWidget implemented in the GWTP application. How is it possible for a non GWTP presenter to show a popup and make sure all life cycle events are properly called.
I know it's a broad question but I'm looking to see if any body has ever tried to integrate two such applications together. If not is there any advice on how to approach this problem at all.
Thanks in advance
In that kind of context, I would suggest to build your home made mvp framework. It would be easier and cleaner than using a subset of the capabilities of GWTP.
That being said, it's not imposible, but you will have to use a complete hierarchy of presenter / presenter widgets. But that won't mean that the lifecycle will work... The lifecycle of GWTP is strongly tied to internal Navigation Events and if your application doesn't use this feature of GWTP, you're likely to lose all its advantages.
Here's how you can embed a GWTP application in your own already existing application:
https://github.com/ArcBees/GWTP/wiki/Website-Embedding
We've already worked on migrating an existing application to GWTP by embedding the existing application IN GWTP while gradually migrating the existing code base, but not the other way around.

GWTP - How to create multiple views depending on formfactor?

How can I create different views for mobile, tablet and desktop using GWTP?
Do I have to have different Ginjectors?
For a mobile presenter i may have more or less presenters, or some functions may be more or less. how can that be handled?
You can have a ClientGinjector interface and inherit it in multiple interfaces like a DesktopGinjector,TabletGinjector and so on. You can then create different bindings for your presenters and views. GWTP makes it easier to handle such a scenario. There is an open-source Customer Experience framework which has a sample to create a mobilewebapp using GWTP. You can check it out here- http://code.google.com/p/gwt-cx/

How Build GWT Application using MVP

I have great experience in programming by using java and other languages.
I need anyone who has great experience in using GWT with MVP to explain how to build GWT Application using MVP:
View package : explain what should be in view class.
Client Package: explain what java files are supposed to be here and what is the benefit from each file.
Server Package: I think here all services files( RPC ).
Activity Package: Explain what is the benefit from the classes here , I think here we we connect events with controls in view classes( Am I correct?).
Place Package: I need to understand this very well.
Also what is the benefit from Clientfactory java file?
what is eventbus?
what is placecontroller?
please if you can order which file should be coded one after another?
Thank you in advance,
1) View is a widget with link to its presenter. It should notify presenter about ui events which should be processed.
2) Views, presenters, client(not shared with the server side) model, places, activities, PlaceHistoryMapper, ActivityMapper. About benefits see below.
Are you understand presenters well? According to your question i assume you confuse it with activities.
1.1 ) Presenter creates and manages view, makes rpc and most of 'logic' stuff.
3) You are right, server package is just a java server logic.
4) Activities link places and presenters. I will return to describing activities below.
5) Place has name, token and own Tokenizer which transforms its place to a token and other way round.
6) I didn't use ClientFactory. I prefer dependency injection with google-gin(gwt client version of guice)
7) Event bus is... I couldn't describe better than official javadoc does :)
Dispatches Events to interested parties. Eases decoupling by allowing objects to interact without having direct dependencies upon one another, and without requiring event sources to deal with maintaining handler lists. There will typically be one EventBus per application, broadcasting events that may be of general interest.
8) PlaceController knows where you are(in application :) and may change current place. (obviously, it has getWhere() and goTo(Place) methods)
9) Firstly you need to code application's singletones like PlaceHostoryMapper and ActivityMapper.
PlaceHostoryMapper provides history and converting tokens to places by segregating all PlaceTokenizers.
ACtivityMapper segregates all places and activities and provides second ones by first ones.
Views and presenters are based on interfaces. Next I would declare such interfaces.
Then write places. Then you able to code activities because you have places and interfaces of presenters.
Then in any order implement views and presenters, map activities to places in ActivityMapper and register PlaceTokenizers in PlaceHistoryMapper.
I assume now you have more questions, feel free to ask in comments or by contacts in my profile :)

GWT - Create something like MobileWebApp using GWTP

I am trying to create an application which will have different views for mobile, desktop and tablet. It is on the lines of MobileWebApp sample from GWT. I am looking at GWT MVP tutorial and have a basic app working.
I was thinking if I should use GWTP and if there would be any advantages of using GWTP instead of GWT MVP(activities and places)
Also, any ideas how different views would bind to the same presenter. There might be differences in what features are available on mobile view and desktop view.
I have done something like this, although at a time before Activities and Places. So back then I've written the MVP framework myself. I placed all the common code, such as Presenters, TransferObjects and Utilities in a separate GWT module. Then each UI became a separate project as well, holding it's View classes and UiBinder stuff, inheriting from the common module. So actually each UI project is a complete GWT application. The GWT applications have to be deployed under different context, thus have different URLs. You then need some smart JavaScript on your welcome page to redirect a visitor depending on there device.
I don't think you can solve this in one GWT app. Or you'd have to come up with a really really clever solution using Deferred Binding (probably it's replacement functionality) and the Linker subsystem.
You can create different views in for a presenter in gwtp. GWTP makes it easier to handle such a scenario. There is an open-source Customer Experience framework which has a sample to create a mobilewebapp using GWTP. You can check it out here- http://code.google.com/p/gwt-cx/

MVP or activities & places, for GWT 2.2

I've been looking into GWT and MVP recently and to be honest I'm very confused. My project will include around 40 different places or views all together. While reading multiple tutorials, some follow Model-View-Presenter and others use Activities and Places, all under the subject of MVP, GWT.
I'm not sure what to follow for a new MVP, GWT 2.2 project.
Many thanks,
Alex
Alex,
Activities and Places are Google's implementation of the MVP framework. There are many well established additional MVP frameworks for GWT which encompass many additional features not yet incorporated into GWT. The two I would recommend are:
GWT Platform: http://code.google.com/p/gwt-platform/
MVP4G: http://code.google.com/p/mvp4g/
They have many additional features to reduce the amount of boilerplate code you have to write to implement solutions. They are worth a peak before choosing Google's A&P.
Cheers
Gene
Activities and Places is the MVP solution that was implemented in GWT 2.2. Before that, MVP was only a recommended approach without an official framework provided by Google. That's why you're getting confused.
I would recommend you to stick with Activities and Places, since it's the official Google solution for MVP.
I hope it helps.
It turns out that an Activity takes the role of a Presenter in the MVP design pattern. Not all of your presenters need to be Activities, but if you have an Activity you can think of it as being a special kind of Presenter with a well-defined lifecycle used for transitions from one "place" to another.
So it's not a choice between MVP and "activities & places". Rather, they're all of the same idea. The new activities & places framework is just a refinement.
Alex,
Activities and Places (as well as ActivityMapper and more) are classes which the GWT team provided to formalize their earlier MVP pattern recommendations. Some time ago I've tried the "raw" MVP recommendations and am currently using the higher-level approach the aforementioned classes provide. It certainly feels easier to use the new classes. In addition to a nice MVP abstraction, you get the important aspect of handling browser history navigation in your application practically for free.
The MVP API is here to stay, it seems, so if you're using GWT 2.2.x I'd also recommend utilizing the new MVP classes from the inception of your project.
Activities and Places are not a MVP framework! Google removes this "disturbance" in later docs. it is just a browser history framework (to easily (de)serialize state of the app). but on implementing MVP and using A&P it turns out that in many cases it is a good idea to merge activity and presenter.
in a more general case one activity could start n presenters.
We used activities and places along with presenters in our design. We also used MVP.
The setup was a view, viewImpl, and inside the view interface, if needed, was a presenter interface that was also declared. The view interface was a pass through to the viewImpl implementation class. The activity went to the viewImpl based on it's business logic and in our case, the viewImpl went to a stand-alone composite widget.
If it was needed, the composite widget used a presenter to get back (another pass through) to the activity. No business logic was in the view or the viewImpl by the way, that was only in the activity. It worked well!