My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
MVP  

Featured
Updated Aug 20, 2010 by joe...@gmail.com

#How to use GWT Pages with the MVP pattern

Introduction

The MVP pattern is a great way of speeding up testing since it allows the functional aspects of the application to be tested without actually testing the UI portion of the code. The binding of the View from the Presenter is done using the page loader.

With this said, GWT Pages does not force you to use the MVP pattern because it can be too much overhead if you are just creating a simple prototype or small application. Not using MVP is a simple as registering your page and returning "this" with the Page.asWidget() method call.

Details

It is fairly simple, when registering pages with the page loader, you provide an additional parameter specifying the display or view class. For example,

  public class MyPageLoader extends StandardPageLoader {
    public void registerPages() {
      registerPage("myPageToken", MyPageClass.class, MyViewClass.class);
    }
  }

or, if you would like to provide additional page attributes...

  public class MyPageLoader extends StandardPageLoader {
    public void registerPages() {
      PageAttributes attributes = new PageAttributes();
      attributes.put("foo", "bar");
      registerPage("myPageToken", MyPageClass.class, MyViewClass.class, attributes);
    }
  }

Modify the Page Classes

The page classes will be instantiated using deferred binding so the page loader must be instantiated using GWT.create(MyPageLoader.class). The view can be provided to the page class in either of the following ways (checked in this order)

  1. setDisplay(...) method
  2. setWidget(...) method
  3. single argument constructor that is compatible with the view class
You also need to make sure that you return your view object in the asWidget() method on the page class.

Powered by Google Project Hosting