Question

We've been using the recommended GWT approach of building parts of our application in an MVP manner. The logic we use is based on Google's examples - the Presenter fetches/prepares data and sets it on the View, and the View contains a reference to the Presenter which it calls (e.g. in UiHandlers).

Some parts of the application which we built should be reused in other views. For example - a view which is sometimes the "main view" of a part of the application - can be used inside a pop-up in another part of the application (of course, the views/presenters are initialized differently in this other case, but basically it is the same thing).

What would be the correct approach to do stuff like this? I cannot seem to find a suitable one without resorting to ugly hacky stuff.

For example - if I put the presenter of the reused component inside the main view - it is easy to initialize the reused component, but it is ugly to receive a result back in the main presenter. This can be solved by passing a runnable or creating a custom handler or passing the parent presenter itself to the reused presenter.

All of these approaches don't seem right to me though and seem ugly. Any ideas/experiences?

Was it helpful?

Solution

What you're describing is a view being able to be controlled by 2 distinct presenters. Abstracting those presenters behind a common API, in the form of an interface, should be enough.

You can also see it as a composite widget being used within two distinct views. The composite widget would then expose events and a public API that both views could wire to their specific presenters.

OTHER TIPS

See Activites and Places,It can help you to desing and structure you app.

https://developers.google.com/web-toolkit/doc/latest/DevGuideMvpActivitiesAndPlaces .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top