Skip to content

Spring Roo and GWT: Like Peanut Butter and Chocolate

May 20, 2010

One of the more interesting announcements to come out of Google I/O is that Spring Roo now supports integration with the hot-off the-pres GWT 2.1 M1 release. GWT 2.1 supports new data presentation widgets and adds formal support for the MVP framework.

I had not heard of Roo before the Google announcement – and downloaded it to give it quick spin. It passes the 10 minute test with flying colours.

Roo addresses the biggest  GWT pain point:  Namely, that there is a lot of tedious boilerplate code required for a GWT application (DTO objects, views, presenters,etc.). Roo does a nice job of generating the majority of this code and supports further modifications and “round tripping” to keep everything in sync.

Here is an example using the Roo shell where we take an existing entity (called “Person”) and add a new date field (“lastUpdate”) to the entity. Notice how Roo modifies the existing domain and view objects.

focus --class ~.domain.Person
~.domain.Person roo> hint
At this stage of the project, you have a few options:

  * List all hint topics via 'hint topics'
  * Create more fields with 'hint fields'
  * Create more entities with 'hint entities'
  * Create a web controller with 'hint controllers'
  * Create dynamic finders with 'hint finders'
  * Setup your logging levels via 'hint logging'
  * Run tests via Maven (type 'perform tests')
  * Build a deployment artifact (type 'perform package')
  * Learn about Eclipse integration by typing 'hint eclipse'
  * Add support for Google Web Toolkit via 'hint gwt'
  * Discover all Roo commands by typing 'help'
~.domain.Person roo> field

field boolean          field date             field email template   field enum             field number           field other
field reference        field set              field string
~.domain.Person roo> field date --

~.domain.Person roo> field date --fieldName lastUpdate --type java.util.Date
Managed SRC_MAIN_JAVA/com/my2do/idm/domain/
Managed SRC_MAIN_JAVA/com/my2do/idm/domain/Person_Roo_JavaBean.aj
Managed SRC_MAIN_JAVA/com/my2do/idm/domain/Person_Roo_ToString.aj
Managed SRC_TEST_JAVA/com/my2do/idm/domain/PersonDataOnDemand_Roo_DataOnDemand.aj
Managed SRC_MAIN_JAVA/com/my2do/idm/gwt/scaffold/generated/
Managed SRC_MAIN_JAVA/com/my2do/idm/gwt/scaffold/generated/
Managed SRC_MAIN_JAVA/com/my2do/idm/gwt/scaffold/generated/PersonDetailsView.ui.xml
Managed SRC_MAIN_JAVA/com/my2do/idm/gwt/scaffold/generated/
Managed SRC_MAIN_JAVA/com/my2do/idm/gwt/scaffold/generated/PersonEditView.ui.xml
Managed SRC_MAIN_JAVA/com/my2do/idm/gwt/request/
~.domain.Person roo>

What isn’t obvious from the above example is that the Roo shell has smart TAB completion everywhere. It is super easy to navigate and figure out what options a command takes.  The ~ (tilde) notion you see above is short hand for the root package name.

Roo generates a vanilla maven project  (there is no black magic going on)- so you can open this up in your favorite IDE.  The generated code uses the MVP pattern that is arguably a best practice for GWT applications.  A lot of people have been struggling with the mechanics of structuring an MVP application (I know I have) – so this should really help.

After the first 10 minutes, I’m really impressed 🙂

  1. May 20, 2010 6:08 pm

    it must be my lack of knowledge pertaining to gwt but i cannot compile this to a gwt app like Ben Alex did in the presentation. what is my entry point module?

    • wstrange permalink*
      May 20, 2010 6:29 pm

      Hmmm……. It “just worked” for me.

      I am running in GWT hosted mode (run the maven target gwt:run). The module entry point is
      generated by Roo – so you should not have to set that. For my test it generated an entry point “com.xxxxx.gwt.ApplicationScaffold” (where xxxx is your app path).

  2. May 25, 2010 8:06 am

    Yes, its easy to create project, but for me as a person who first time working with GWT number of classes created by ROO is overwhelming – they are badly formated, contains comments from Google IO presentation (” Application for browsing the entities of the Expenses app.”,), and inserted in packages in way that for me is hmm quite confusing (i know this is still M1). And according to GWT documentation its looks much more simpler – but as I said, i have no experience in this matter. Just thought that it will help me to jump into GWT world easier – well, is not.

  3. ashton permalink
    July 8, 2010 4:41 pm

    I would recommend looking at a GWT only sample (the mail client) and then looking at a Roo only app then the Roo + GWT app

    Once you create a Roo/GWT app you must enable gwt settings (right click project > google > web toolkit settings… > make sure Use Google Web Toolkit is selected and hit Okay)

    You need to make sure you have GWT – 2.1.0.m1 as well as roo-1.1.0M1

    After you fix the settings you can right click and run as “web application”
    (also since this is only M1 adding data doesn’t work well in Chrome)

    I you install the correct SpringSource Tool Suite it will handle all the GWT and Roo dependencies.

    If you want to open a pure GWT app in STS you need to New Java Project from existing source and select GWT sample. Then change gwt settings (right click > google > web toolkit settings > etc)

    It is very hard to jump into GWT from spring roo but it is worth it

  4. Neeru permalink
    August 2, 2010 1:43 am

    Please tell me how we set the time filed in spring roo project.?

Comments are closed.

%d bloggers like this: