Re: GWT and MVP

170 views
Skip to first unread message

David

unread,
Oct 18, 2012, 10:36:59 AM10/18/12
to google-we...@googlegroups.com

You should be able to find what you are looking for under "Large scale application development and MVP - parts 1 and 2"

I've long since abandoned the notion of hiding my pojos from my views so I guess I'm in MVC denial.     



On Wednesday, October 17, 2012 5:28:16 PM UTC-4, furious_panda wrote:
Hi,

I need some help, I did not found examples or forums discussions about these subjects.

I want to try to do a GWT application using MVP pattern. But I have some difficulties.

In MVP, Presenter have to contain Display interface that specifie what the View must implements and return.

I have two problems when I apply this pattern:

1 - The View must not have to manipulate Model. Or, how it is possible for a collections of objects?

For example, I have model  object Person as follows:

public class Person{
    private String firstname;
    private String lastname;
    private Integer age;
......
}

The View must display a collection of Person in Table (Flextable for example) whithout manipulating Model. How it is possible ?

This is my presenter, and what I do now:

public class PersonListPresenter extends WidgetPresenter<PersonListPresenter .Display> {
     public interface Display extends WidgetDisplay{
public void setData(List<Person> data);
    }
    
    protected void onBind() {
           display.setData(data);
    }
}

This is my view, and what I do now:

public class SongsView implements PersonListPresenter .Display {
......
public void setData(List<Person> data) {
   if(data!=null && data.size() > 0){
for (Person person: data) {
              // I display all information about each Person in one row of table     
                  
         }
    }
}
.....
}

How can I do in MVP for this case ?

2 - My second problem, is each row of this table must be clickable ? How I can do ?

How can I get from display click event for each row ?

public class PersonListPresenter extends WidgetPresenter<PersonListPresenter .Display> {
     public interface Display extends WidgetDisplay{
public void setData(List<Person> data);
    }
    
    protected void onBind() {
           display.setData(data);
           // I have to implement the same information for each row but the source information is different.
           // I have to fire an Event containing the Person information that is clicked
           display.get ????? 

                   .addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {

                        }
              }
    }
}

Thanks in advance.

Thad

unread,
Oct 18, 2012, 11:25:13 AM10/18/12
to google-we...@googlegroups.com
I have not been hard and fast about hiding POJOs from my my views. After all, a view has to know what to display and I find oodles of getFoo() are a lot work for the return. However I put all updating of my POJOs in my activities. Each time the view need to display something, it gets it from the activity. The activity handles setDirty(true|false). This seem easiest for my mind to grasp.

2 - My second problem, is each row of this table must be clickable ? How I can do ?

How can I get from display click event for each row ?

public class PersonListPresenter extends WidgetPresenter<PersonListPresenter .Display> {
     public interface Display extends WidgetDisplay{
public void setData(List<Person> data);
    }
    
    protected void onBind() {
           display.setData(data);
           // I have to implement the same information for each row but the source information is different.
           // I have to fire an Event containing the Person information that is clicked
           display.get ????? 

                   .addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {

                        }
              }
    }
}

Thanks in advance.

If your using a FlexTable, look at samples/Mail for how this is done. I've implemented something akin to this many times (though now I'm moving larger data sets to cells).

furious_panda

unread,
Oct 19, 2012, 4:15:21 PM10/19/12
to google-we...@googlegroups.com
Thanks all yours responses.

Fabio

unread,
Oct 20, 2012, 5:41:56 AM10/20/12
to google-we...@googlegroups.com
Hello

In simple words:

The View must implements the page as users are going to see it, that is the graphic part of the project, that is again you build the page of objects to show when users load the page.
The Presenter , (who is a Presenter?), hands its own view.
So the presenter gets all the needed objects from its own view (created inside the constructor or passed as parameter) and hands them according its need.
So you build your graphic page in a View and the presenter will use it. Keep in mind that the view must implements all the Getter that return the needed Widget to hand.

When user click i.e. on a Button, its click handler will build a new Presenter, that will show its view. Infact all presenter must show its Widget (your graphic page) got by the method that all view
must implement, asWidget(), but as a View extends usually a Composite, it is alread done.

is that clear ?

the way you did is quite correct, I agree 50%.

At the beginning you build the page with Persons. It's Ok.

Then maybe you will need new Persons and i.e. make a server request to get all Persons i.e. from a DB.

Yes setData will make this.

Keep in mind that you are not handling anything if setData is a more complext algorithm. It doesnt mean that your are making logic code inside it.

B  U   T
maybe you'd better to GET the table from the View and write the setData inside the presenter.
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/xortaej27p4J.
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.

Reply all
Reply to author
Forward
0 new messages