Extending the 'Contact: MVP' example

8 views
Skip to first unread message

Andrew

unread,
Feb 26, 2010, 5:18:22 PM2/26/10
to Google Web Toolkit
Hey all. I've got a question about the GWT and more specifically the
mvp architecture tutorial

http://code.google.com/webtoolkit/doc/latest/tutorial/mvp-architecture.html

I've been messing around with this, and extending it for my own
project, but i've run into a little problem.

if (token != null){
Presenter presenter = null;

if (token == "user"){
presenter = new UserPresenter(userRpcService, eventBus, new
UserView());
}
if (token == "edit"){
presenter = new EditUserPresenter(userRpcService, eventBus, new
EditUserView());
}

if (presenter != null){
presenter.go(root);
}


In this code, we are passing the root panel to the presenter in order
to tell it which panel to attach to. The problem is that I've tried
attaching a couple of vertical panels to the root panel, then passing
those into separate presenters so that I can display multiple
presenter simultaneously, but it doesn't work. When the app loads, it
will load all the seperate panels successfully, but when it tries to
switch between the UserPresenter and the EditUserPresenter, all my
other panels are removed from the screen.

Does anyone have an answer for me why this won't work? I'm pretty
stumped right now. Thanks!

Jim

unread,
Feb 26, 2010, 8:06:57 PM2/26/10
to Google Web Toolkit
modify Presenter.go(HasWidget container) to Presenter.go(HasWidget...
containers).

On Feb 26, 5:18 pm, Andrew <zmo...@gmail.com> wrote:
> Hey all. I've got a question about the GWT and more specifically the
> mvp architecture tutorial
>

> http://code.google.com/webtoolkit/doc/latest/tutorial/mvp-architectur...

Andrew

unread,
Feb 27, 2010, 11:32:55 AM2/27/10
to Google Web Toolkit
The idea is to have multiple presenters throwing views up into their
own little piece of real estate on the screen, then depending on
different events, swap out presenters. For instance I want user
information in one little box on the screen, and a header across the
top. I want the user information screen to disappear and show a modify
user screen in it's place when they click the modify user button, but
I don't want anything to happen to the header when that happens. I
have a different presenter for each piece of the application, for
instance the User Screen, a Header, a part that shows a list of items.
I already tried to do this, but when an event happened, a new screen
would show and wipe out another one. In my case the modify user button
was clicked, and it wiped out the header.

I don't know how passing multiple containers to a presenter would
solve this problem unless it was just a reference to a structure that
was housing all of them. For instance a whole DockPanel gets passed
down to each presenter and they all add themselves to the dock panel.
I might try that and see what happens, but if anyone else has a better
idea please let me know!

Andy

Brian Reilly

unread,
Mar 18, 2010, 1:06:41 PM3/18/10
to Google Web Toolkit
It seems to me like you need a supervising presenter to coordinate
interactions among each of the panes of the application, in a
DockPanel as you suggest. The AppController would then bootstrap this
instead of managing what is shown in the root panel. Finally, the
logic that is in the AppController of the Contacts example would need
to be pushed down into this presenter or something that sits between
that and the contacts widget.

Doing this, though, removes a lot of responsibility from the
AppController. I don't know that the AppController is a bad idea. It
may be useful for a simple example. However, I think it would be more
useful to have a more self-contained contacts widget that could be
reused without having to worry about the AppController.

I haven't tried any of this myself yet, but I've been thinking about
similar issues related to managing view state when composing widgets
using MVP.

-Brian

Fabio Kaminski

unread,
Mar 18, 2010, 1:29:57 PM3/18/10
to google-we...@googlegroups.com
As far as i understand you have "windows" that contain widgets... like:

MainWidgetContainer (which owns) LoginWidget, HeaderWidget and so on..
LogoutWidgetContainer (owns) LogoutWidget, ComeBackSoonMessageWidget, etc.. 

if is that the case, you would only call the go() which means "RootPanel.get().add()"
when you wanna change from one widget container to another... MainWidgetContainer <-> LogoutWidgetContainer
not LoginWidget > HeaderWidget or LogoutWidget...

as soon you establish this rule (you can even restrict go() method to allowing only widget containers)
if you dont do it yet.. the only thing you need ins to assemble the Containers.. like:

public class MainView extends Composite implements Display {
  
   final LoginView loginView;
   final HeaderView headerView;

  (add those to this widget) 
  (...)
}

Fabio Kaminski

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


Sean C.

unread,
Apr 10, 2010, 3:24:15 PM4/10/10
to Google Web Toolkit
Having a similar problem with creating Composite Views backed by their
respective Presenters.

The bug in DockPanelLayoutPanel for Java 5 does not help and I don't
have the option to switch to Java 6 but that is a separate discussion:
http://code.google.com/p/google-web-toolkit/issues/detail?id=4254

Back to the problem: the Home Page is composed of three columns with
the East and West columns being static HTML + CSS as well as some
dynamic content (Vertical Panels), that affects the content of the
Center column. Yes, JSNI is being used here.

E.g: clicking the Login button in the West column presents a Login
form in the Center column. The Home Page is one View + Presenter but
the Login form is a separate View + Presenter. They do not play
together and the Home View + Presenter always override the other Views
+ Presenters. Even tried placing separate DIV hooks in the HTML page
to get the different views to attach to different nodes in the DOM but
to no avail.

Several options that are being tried and tested:
1. Play directly with the DOM (class) to swap widgets but then you
just end up having one View + Presenter and a lot of widgets.
2. Creating a parent class for all Views and Presenters that contains
the logic and content for the East and West Panels and then attach the
new Views directly to the RootPanel. This is defeating the purpose of
AJAX as it is equivalent to redrawing the page with the exception of
the static parts.
3. Go back to the drawing board by looking at the options available:
http://martinfowler.com/eaaDev/uiArchs.html

Derek Greer has something that might inspire:
http://www.aspiringcraftsman.com/2007/08/interactive-application-architecture/

A .NET centric post about this: http://bradwilson.typepad.com/blog/2008/06/composite-views.html

Dolphin SmallTalk based discussion on Composite MVP:
http://www.mimuw.edu.pl/~sl/teaching/00_01/Delfin_EC/Patterns/CompositeMVPComponent.htm.

Sean C.

On Mar 18, 1:29 pm, Fabio Kaminski <fabiokamin...@gmail.com> wrote:
> As far as i understand you have "windows" that contain widgets... like:
>
> MainWidgetContainer (which owns) LoginWidget, HeaderWidget and so on..
> LogoutWidgetContainer (owns) LogoutWidget, ComeBackSoonMessageWidget, etc..
>
> if is that the case, you would only call the go() which means
> "RootPanel.get().add()"
> when you wanna change from one widget container to another...
> MainWidgetContainer <-> LogoutWidgetContainer
> not LoginWidget > HeaderWidget or LogoutWidget...
>
> as soon you establish this rule (you can even restrict go() method to
> allowing only widget containers)
> if you dont do it yet.. the only thing you need ins to assemble the
> Containers.. like:
>
> public class MainView extends Composite implements Display {
>
>    final LoginView loginView;
>    final HeaderView headerView;
>
>   (add those to this widget)
>   (...)
>
> }
>
> Fabio Kaminski
>

> > google-web-tool...@googlegroups.com<google-web-toolkit%2Bunsu...@googlegroups.com>

Brian Reilly

unread,
Apr 12, 2010, 2:13:47 PM4/12/10
to Google Web Toolkit
I think you should be able to do this pretty easily by putting
something that implements HasWidgets (such as SimplePanel, FlowPanel,
etc.) in your center column. You can then pass that container into
your presenter as the place where its content should live. That should
leave the other things that you've added to the RootPanel in place
when you switch presenters for the center column.

-Brian

> Derek Greer has something that might inspire:http://www.aspiringcraftsman.com/2007/08/interactive-application-arch...

> Dolphin SmallTalk based discussion on Composite MVP:http://www.mimuw.edu.pl/~sl/teaching/00_01/Delfin_EC/Patterns/Composi....

> > > google-web-tool...@googlegroups.com<google-web-toolkit%2Bunsubs cr...@googlegroups.com>

Sean C.

unread,
Apr 13, 2010, 11:15:28 AM4/13/10
to Google Web Toolkit
The problem is that only one presenter can be active at a given time.
If a presenter is controlling the left, right and center column, even
handing the center column container to another presenter will not
result in the original presenter giving up control or you get the
effect of one view being drawn followed by the second view quickly
replacing it.

I ended up implementing the left and right columns as pure HTML+CSS
and used JSNI or the History mechanism to trigger the appropriate View
+Presenter to affect the center column. This way no presenter is
controlling the left and right columns.

Sean C.

Josh

unread,
May 27, 2010, 1:04:10 AM5/27/10
to Google Web Toolkit
I to would like to use MVP but find that i'm unable to present more
than one view on the screen at a time. I would like to have 3-5 panels
loading widgets based on selections in other panels. I attempted to
create a presenter/view (just to test) that had both contact edit and
contact list. The issue i ran into was the RPC fired i believe but the
view never updated with the data. I haven't use GWT long enough to
know the best way to ask the question but has anyone found a way to
allow more than one View Presenter without creating a single Presenter
to manage each of the views? I Was looking into HMVC but still unsure
how to approach this.

> > > Dolphin SmallTalk based discussion on CompositeMVP:http://www.mimuw.edu.pl/~sl/teaching/00_01/Delfin_EC/Patterns/Composi....

> > > > > > > >mvparchitecture tutorial

Reply all
Reply to author
Forward
0 new messages