Thursday, February 24, 2011

Roo Flex Addon Tutorial

I ran a workshop today at Tikal exploring the new Roo Flex Addon, during this workshop My colleagues Haim Raman, Shay Gabay prepared a short tutorial for using Roo Flex Addon. If you are interested in the full post including our thoughts and conclusion on Roo goto the post page on Tikal's website. Below I've listed the basic steps you need to go through in order to run a simple Roo Flex Application

Getting Required Software

Spring Roo addon is still in early development so using it is tricky, it's not entirely compatible with different Roo versions. In order to run this tutorial you need to get the following artifacts and versions:

spring-roo-1.1.1.RELEASE
Latest running Roo Flex Addon

Installing the software

  • Unzip spring-roo-1.1.1.RELEASE.zip to a desired folder (this will be declared later as your ROO_HOME)
  • Copy the addon jar to ROO_HOME\bundle directory
Make the following changes to your environment variables
  • ROO_HOME = installed roo dir
  • Add ROO_HOME\bin to your path variable

Now open a command shell and create a new directory


mkdir voteFlex
cd voteFle

Open roo shell by typing "roo"

Once the shell is open, you can copy\paste the entire following script, sit back relax and let Roo do it's magic and work for you.

project --topLevelPackage com.tikalk.fuseday.roo --projectName voteFlex
persistence setup --provider HIBERNATE --database HYPERSONIC_PERSISTENT
flex setup
entity --class ~.domain.Choice --testAutomatically
field string namingChoice --notNull --sizeMin 1 --sizeMax 30
field string description --sizeMax 80
entity --class Vote --testAutomatically
field reference choice --type Choice
field string ip --notNull
field date registered --type java.util.Date --notNull --past
flex remoting all --package ~.service

Exit from roo using the exit command and run your new application by calling

mvn tomcat:run
Chances are that you will get some missing dependencies, in order to solve this go edit the /voteFlex/pom.xml and add the following repository to it

<repository>
<id>spring-snapshot</id>
<name>Spring Portfolio Snapshot Repository</name>
<url>http://maven.springframework.org/snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
Thanks to Ken Rimple for solving the above issue.

Now, let go through the script rows and try to understand what Roo is doing


project --topLevelPackage com.tikalk.fuseday.roo --projectName voteFlex

Creates a new Spring Roo project for a given name and top level package name, this line will add the basic files that are required for the project.

persistence setup --provider HIBERNATE --database HYPERSONIC_PERSISTENT

Sets up your persistence layer, use Hibernate as ORM, use Hypersonic as a DB.

flex setup

Setup the project to use Flex as GUI, this line will add Flex dependencies to the project's pom and add a number of Flex features to the build.

entity --class ~.domain.Choice --testAutomatically
field string namingChoice --notNull --sizeMin 1 --sizeMax 30
field string description --sizeMax 80
entity --class Vote --testAutomatically
field reference choice --type Choice
field string ip --notNull
field date registered --type java.util.Date --notNull –past

The above lines create entities and add fields to these entities. These lines will create Hibernate entities, relevant AspectJ scripts and so on.

flex remoting all --package ~.service

The above does the real work, it scafolds the entities and creates Flex GUI that will represent them, it also creates services in the specified ".service" package. It also adds BlazeDS and configures it.

once your tomcat is up and running to go to http://localhost:8080/voteFlex/voteFlex_scaffold.html And see your running application, you can edit and modify both vote and choice entities from your auto created Flex screen.

2 comments:

Jean-Marc Moras said...

Thanks for this tutorial,
As Roo Flex addon is not stable, it was difficult to run it.
See http://forum.springsource.org/showthread.php?98528-Flex-Addon-for-Spring-Roo-Compatibility-Update


Your tutorial works but only with the version of roo and flex add with the link that you gave.

Futhermore I had to solve two problems more than the one you talk about :

1)
You must Add
<pluginRepository> <id>flex-mojos-repository2</id>
<url>http://repository.sonatype.org/content/groups/flexgroup</url>
</pluginRepository>
to the pom.xml

2) You must change the version of spring-flex xsd to spring-flex-1.5.xsd
into flex-config.xml
(http://www.springframework.org/schema/flex/spring-flex-1.5.xsd"> )

Have fun with Roo+Flex

Lior Boord said...

@Jean-Marck, thanks, I'll look into the problems you specified and might add your solutions to the tutorial.