GWT 2.1 MVP & Client Factory Example

So if you’re a Java developer and not been hiding under a rock recently, you’ve probably heard of the Google Web Toolkit (GWT).  It’s been around for a few years, and it provides some wonderful capabilities to develop applications in Java that get compiled to Javascript and are cross-compatible on all browsers.

GWT 2.1 is still under development but GWT 2.1 RC 1 was released a few days ago and we’re well excited.  They’ve got some wonderful new classes and interfaces like Activities, Places and EventBuses which help manage complex applications.

I won’t get into all the detail, but there are some great articles to start you off which can be found here:

The only thing is about the above articles is that the first one identifies how to use Activities & Places using the new GWT 2.1 architecture.  However, the second and third articles, although brilliant, are using a slightly different architecture and are focusing on event buses, rather than GWT 2.1.  The second and third ones do however provide a lovely Contact Details example code which works straight out the box and shows how the events work.

As a little bit of help to the community, I applied the GWT MVP in 2.1 (Places, Activities and a Client Factory) with the Contact Details example which was brilliantly provided by Chris Ramsdale from the Google Developer team.  My updated code can be downloaded here.

In case you’re interested in the original Contact Details example from google, that file can be found here.

The changes I’ve made are as follows:

  • Integrated the new ClientFactory class required to pass the EventBus and PlaceController around
  • ClientFactory can also be used to get references to the views
  • I’ve replaced the HandlerManager with the new EventBus class used in GWT 2.1
  • I’ve ditched the AppController class for the new GWT 2.1 PlaceController
  • Presenters are no longer called presenters, instead they use Activities
  • Added the AppActivityMapper and the AppPlaceHistoryMapper classes recommended for GWT 2.1
  • Created three new places ContactPlace, EditContactPlace and NewContactPlace which can be used for accessing the url based locations
  • No longer use events to jump from url to url, now use the PlaceController to go to new Place

So that’s it. I hope you have found that useful.  If you have – please let me know by adding a comment and I’ll gladly answer any questions you may have.