Home > JavaEE > Playing with Spring Roo and Vaadin

Playing with Spring Roo and Vaadin

One year ago, under the gentle pressure of a colleague, I tried Spring Roo. I had mixed feelings about the experience: while wanting to increase productivity was of course a good idea, I had concerned regarding Roo’s intrusiveness. I left it at that, and closed the part of my memory related to it.

Now, one year later, I learned that my favourite web framework, namely Vaadin, had set their sight on a Roo plugin. That was enough for me to get back on my feet and try again. This article tries to describe as honestly as possible the good and the bad of this experience related to both Roo and the Vaadin plugin.

Pure Roo

First of all, I download the free STS 2.5, that includes Roo 1.1.1 and install it. No problem at this time. Then, I create a new Spring Roo project inside STS. Unluckily, STS does not create the default maven directories (src/main-test/java-resources): errors appear in my Problems tab. Trying to solve the project, I type the project command into Roo’s shell inside STS. Roo complains I should give it my top-level package, though I already did that with the wizard. OK, I am a nice guy and do as asked:

project --topLevelPackage ch.frankel.blog.roo.vaadin

This time, Roo successfully creates the aforementioned directories as well as a Spring configuration file and a log4j properties file.

Next step is to create my persistence layer. The use of CTRL+SPACE is real nice and helps you much with command parameters. Combined with hint, it’s real easy to get comfortable with Roo.

persistence setup --provider HIBERNATE --database DERBY

Roo nicely updates my Maven POM and let it download the latest version right dependencies (JPA, Hibernate, Derby, etc.). I can always change version if I need a specific one. It even adds JBoss Maven repo so I can download Hibernate. I just need to update my database properties, driver and URL. Uh oh: when I open the file, I see Roo has strangely escaped colons characters with backslash. I just replace the example escaped URL with an unescaped real one.

Meanwhile, I notice an error in the log: “The POM for org.aspectj:aspectjtools:jar:1.6.11.M1 is missing, no dependency information available”. Roo updated my POM with version 1.6.11.M1. If I check on repo1, the latest version is 1.6.10. Replacing 1.6.11.M1 with 1.6.10 removes the error.

Now would be a good time to create my first entity:

entity --class ~.entity.Teacher --testAutomatically

STS now complains that the target directory doesn’t exist, like before it complained for source directories. In order to remedy to that, I just do as before, I launch an instruction. In this case, I order Roo to launch the tests with the perform test command. In turn, Roo launches mvn test under the hood and Maven does create the target directory.

Entities without fields are useless. Let’s add a first name and a name to our teacher.

field string --fieldName firstName
field string --fieldName name

It would be cool to have courses attached.

entity --class ~.entity.Course --testAutomatically
field string --fieldName name
focus --class Teacher
field set --fieldName courses --type Course

Notice that since Roo works in a contextual manner, I have to use the focus command so that I do not create the courses Set inside the Course class but inside the Teacher class.

Vaadin plugin

Until now, there was nothing about Vaadin. Here it comes: following the instructions from Vaadin’s wiki, I download the latest Vaadin Roo plugin snapshot and put in in my Roo local OSGI repository. In order to the new bundle to be seen by Roo, I have to restart it which I don’t know how to do inside STS. Instead, I restart STS.

There comes the magic command:

vaadin setup --applicationPackage ~.web --useJpaContainer false

This command:

  • adds Vaadin dependency
  • adds web directory with images
  • updates the POM to war packaging

Yet, when I try to add my new web project to Tomcat, STS complains it doesn’t find candidate projects. The problem lies in that Eclipse is not synchronized with Maven and as such, my project lacks the Web facet. The solution: right-click on my project, go to the Maven menu and click on “Update project configuration” submenu. When done, I can add the project to Tomcat like any other web project (since it is anyway).

Starting Tomcat and going to http://localhost:8080/vaadin, I can see Vaadin handling my request. I just miss the views over my entities, which is done with the following:

vaadin generate all --package ~.web.ui --visuallyComposable true

Conclusion

Well, that was quick, if not perfect. I do miss some features in Roo:

As for the Vaadin plugin, it lacks updating Eclipse files after having changed the POM. Someone not familiar with m2eclipse inner workings could lose some time with this behaviour.

On the other hand, I have a simple webapp in a matter of minutes, that I can now update how I choose. CTRL+SPACE and hint are Roo killer features. Moreover, like the Vaadin add-on showed, you can add whatever functionality is lacking with your own plugin (or use one already available). What’s really important for me though, and without it, I wouldn’t even consider using Roo is that it is completely removable in 3 easy steps. As such you can use Roo’s productivity boost, not tell anyone and remove Roo just before passing your project to the maintenance team.

Thanks to Joonas Lehtinen and Henri Sara for their work on Roo Vaadin’s plugin and sending me ahead of schedule the wiki draft explaining the Vaadin part.

Here are the sources for this article in Maven/STS format.

To go further:

email
Send to Kindle
Categories: JavaEE Tags: , ,
  1. January 18th, 2011 at 23:50 | #1

    I am a new Vaadin and Roo user -> how would I add a new field to the Teacher Entity? For example a Description (as a Rich Text Area in Vaadin)

  2. nemesisqp
    January 20th, 2011 at 07:34 | #2

    It seem the project generated have encoding problem, I can’t use utf-8 text, do you have this problem ?

  3. Barton
    January 20th, 2011 at 16:39 | #3

    Thanks for writing this up. I’m having troubles with Vaadin plugin – I’m not able to get the “vaadin setup” working in roo – roo doesn’t recognize it.

    I installed STS 2.5.2 with Roo 1.1.1. I downloaded the com.vaadin.spring.roo.addon-0.9.1.BUILD-20101220.095953-1.jar and placed it in the springsource/spring-roo-1.1.1.RELEASE/bundle director and restarted STS. When I try roo with the “vaadin setup” it reports ‘vaadin setup’ not found.

    Any ideas?
    Barton

  4. Janez Lavrič
    January 21st, 2011 at 12:26 | #4

    Hi, I’m having the same problem. Barton have you found any solution? Janez

  5. jcano
    January 24th, 2011 at 00:27 | #5

    @Janez Lavrič
    so do I :(…

  6. Barton
    January 25th, 2011 at 12:45 | #6

    From Henri Sara (author of plugin)

    roo>osgi uninstall –bundleSymbolicName com.vaadin.spring.roo.addon

    roo>osgi install –url https://oss.sonatype.org/content/repositories/vaadin-snapshots/com/vaadin/com.vaadin.spring.roo.addon/0.9.1.BUILD-SNAPSHOT/com.vaadin.spring.roo.addon-0.9.1.BUILD-20110113.132028-5.jar

    roo>osgi start –url https://oss.sonatype.org/content/repositories/vaadin-snapshots/com/vaadin/com.vaadin.spring.roo.addon/0.9.1.BUILD-SNAPSHOT/com.vaadin.spring.roo.addon-0.9.1.BUILD-20110113.132028-5.jar

    Restarting Roo after installing or upgrading the plugin is also a good idea if you are having problems.

  1. No trackbacks yet.