Lajos is a java developer and occasionally a trainer at EPAM System. He's highly interested in developer productivity, web frameworks, and cloud computing. He is a passionate father and rock climber. Lajos has posted 2 posts at DZone. View Full User Profile

JSF 2.0 with Spring Roo

  • submit to reddit

If you want to create a JSF 2.0 web application in 10 minutes here comes a short how-to.

I never really gave a chance to JSF. With JSF 1.X there was limited tool support, components were quite basic. it didn't really got my attention. I know JSF 2.0 was released more than 2 years ago, so it was long on my todo list.

Lately I am working with spring roo a lot, and as Spring Roo 1.2.0.M1 was released, I read Alan Steward's blog entry which mentioned that the next 1.2 release will include JSF/PrimeFaces support.

I couldn't wait any longer so i went on with the snapshot version, and created a JSF 2.0 webapp. It's pretty impressive, if you want to see the result, i deployed it to CloudFoundry: (if you dont't already have a cloudfoundry account, you should definitely register for a free account)

Screenshot of the deployed JSF 2.0 sample app click here to see it in full size

How to sell your brain?

The other day i was doing a spring roo training and the participants just said: please no more pizzashop examples! So they come up with the idee to create a special ebay for selling organs.

Sure, its probably politically incorrect but caught their attention for the rest of the training. So here we create an 'Organ-bay' in 10 minutes:

- Download the latest snapshot from springsource CI:

 unzip /path/to/
 ROO_HOME=$(readlink -f spring-roo-1.2.0.BUILD-SNAPSHOT)
    ____  ____  ____  
   / __ \/ __ \/ __ \ 
  / /_/ / / / / / / / 
 / _, _/ /_/ / /_/ /  
/_/ |_|\____/\____/    1.2.0.BUILD-SNAPSHOT [rev 1195a76]

Welcome to Spring Roo. For assistance press TAB or type "hint" then hit ENTER.

Once you got the roo shell prompt enter the following commands:

project --topLevelPackage com.organbay --projectName rooj-jsf-app
persistence setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY

enum type --class ~.domain.BloodType 
enum constant --name Group_A
enum constant --name Group_B
enum constant --name Group_AB
enum constant --name Group_0

entity jpa --class ~.domain.Organ
field number --fieldName price --type java.lang.Integer --notNull --min 5
field string --fieldName name --notNull 
field date --fieldName bestBefore --type java.util.Date --dateFormat SHORT --notNull 
field string --fieldName description

entity jpa --class ~.domain.Donor
field string --fieldName name --sizeMax 25 --notNull
field enum --fieldName bloodType --type ~.domain.BloodType --notNull
field date --fieldName birthDate --type java.util.Date --past
field string --fieldName email --regexp "[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]+" --notNull
field set --fieldName organs --type ~.domain.Organ --mappedBy donor --notNull false --cardinality ONE_TO_MANY
field reference --fieldName donor --class ~.domain.Organ --type ~.domain.Donor --notNull

web jsf setup --implementation APACHE_MYFACES --theme  EGGPLANT
web jsf all --package ~.jsf


Now the application is ready to be deployed. The tomcat:run maven goal would be ideal for this purpose. To be able to use JSF 2.0 you would need tomcat 7.x but unfortunately the tomcat maven plugin version which supports tomcat 7 is under development, so i found that its easier to use the cargo plugin:

mvn package org.codehaus.cargo:cargo-maven2-plugin:run -Dcargo.maven.containerId=tomcat7x -Dcargo.maven.containerUrl=

[WARNING] [talledLocalContainer] Oct 26, 2011 5:06:08 PM org.apache.catalina.startup.Catalina start
[WARNING] [talledLocalContainer] INFO: Server startup in 31856 ms
[INFO] [talledLocalContainer] Tomcat 7.x started on port [8080]
[INFO] Press Ctrl-C to stop the container...

now you can reach the webapp in your browser: http://localhost:8080/rooj-jsf-app-0.1.0.BUILD-SNAPSHOT/pages/donor.jsf

Deploy it to the cloud

if you want to share your new shiny webapp on the cloud, you would have several choises: amazon ec2, amazon beanstalk, heroku, cloudfoundry, you name it.

I just choose cloudfoundry, as it has a roo plugin, and it was just 3 lines to deploy it:

cloud foundry login --email --password idonttellya
cloud foundry deploy --appName roojsfpreview --path /target/rooj-jsf-app-0.1.0.BUILD-SNAPSHOT.war
cloud foundry start app --appName roojsfpreview

So there is no more excuse not to give JSF 2.0 a go. I was quite impressed with the generated primefaces app, in terms of eye candy, and features such as:

  • Client side validation based on the JSR-303 annotation attached to the entities
  • AJAX pagination
  • Modal dialog boxes
  • Calendar widget
  • Auto populated dropp-down list for 1:N relation
  • Auto populated dropp-down list for enumartions
  • growl type autohiding popup messages
I was even able to add a theme switcher in a couple of minutes (probably a good canditate to be included into the JSF addon, or maybe a new JSF dependent add-on). Lets start create a JSF 2.0 webapp today!


Keep up with the good work Alan Steward and the entire Spring Roo Team!

spring-roo-jsf-webapp-small.png48.71 KB
spring-roo-jsf-webapp.png85.95 KB
Published at DZone with permission of its author, Lajos Papp.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)



Juan Macias replied on Wed, 2011/11/02 - 3:04am

Very nice indeed. But languages are not working ;)

Ennius replied on Wed, 2011/11/02 - 5:10am

Nice, but why 'web jsf setup --implementation APACHE_MYFACES --theme EGGPLANT' is not working ? i get : Command 'web jsf setup --implementation APACHE_MYFACES --theme EGGPLANT' was found but is not currently available (type 'help' then ENTER to learn about this command)

Charlie Mordant replied on Wed, 2011/11/02 - 5:28am

Is that working with OSGI and REST/WS? i'm trying to implement that combo.

Lajos Papp replied on Wed, 2011/11/02 - 8:54am in response to: Ennius

Please note, that you have to use 1.2.0.BUILD-SNAPSHOT version, i checked it again with the latest one [rev 765f5e7], and the 2 listing is working just fine. please copy your 'log.roo' file and i might figure out the reason.

Ali2 Ebrahimi replied on Wed, 2011/11/02 - 10:06am

I get following error with windows xp latest build.
roo> project --topLevelPackage com.organbay --projectName rooj-jsf-app
Created ROOT\pom.xml
Undo create ROOT\pom.xml
Unknown character property name {r} near index 8

Ansar Basha replied on Wed, 2011/11/02 - 10:30am

I downloaded 1.2.0.BUILD-SNAPSHOT [rev 765f5e7] still giving error line Ali2 Ebrahimi mentioned. roo> project --topLevelPackage com.organbay --projectName rooj-jsf-app Created ROOT\pom.xml Undo create ROOT\pom.xml Unexpected internal error near index 39 C:\spring-roo-1.2.0.BUILD-SNAPSHOT\bin\ ^ Thanks

Ansar Basha replied on Wed, 2011/11/02 - 10:32am

Here is the contents of the log.roo file


// Spring Roo 1.2.0.BUILD-SNAPSHOT [rev 765f5e7] log opened at 2011-11-02 15:26:35
// [failed] project --topLevelPackage com.organbay --projectName rooj-jsf-app

Lajos Papp replied on Wed, 2011/11/02 - 12:41pm in response to: Ansar Basha

Uppps, that happens when you work on snapshots .... looks like you just hit a bug: I'm sure it wont make you happy, but it works on anything, but windows ;)

Lajos Papp replied on Thu, 2011/11/03 - 3:07am in response to: Lajos Papp

you can quickly fix this windows issue, by:

Lajos Papp replied on Thu, 2011/11/03 - 4:22am in response to: Lajos Papp

ROO-2867 is fixed, you can use the latest without any modification.

Roger Itai replied on Thu, 2011/11/03 - 2:03pm


 I got following error when ran Maven:

[ERROR] Failed to execute goal on project telepizza: Could not resolve dependenc
ies for project Fa
ilure to find org.springframework.roo:org.springframework.roo.annotations:jar:1.
2.0.BUILD-SNAPSHOT in was cached in the
 local repository, resolution will not be reattempted until the update interval
of spring-maven-release has elapsed or updates are forced -> [Help 1]

Thanks in advance for any information.

Lajos Papp replied on Thu, 2011/11/03 - 4:49pm in response to: Roger Itai

Hi Roger, The annotations.jar with version 1.2.0.BUILD-SNAPSHOT is missing from you local maven repo. It is part of the dowloaded, so you can install it with the following command:
mvn install:install-file -DgroupId=org.springframework.roo -DartifactId=org.springframework.roo.annotations -Dversion=1.2.0.BUILD-SNAPSHOT -Dpackaging=jar -Dfile=spring-roo-1.2.0.BUILD-SNAPSHOT/annotations/org.springframework.roo.annotations-1.2.0.BUILD-SNAPSHOT.jar

Alan Stewart replied on Fri, 2011/11/04 - 6:57pm

Thanks Lajos for exercising the JSF/PrimeFaces add-on before its release in Roo 1.2 RC1. If you find any issues please log Jira tickets so I can fix them before we release 1.2. I'm constantly making changes and tweaks, so always use the latest Roo snapshot code.

Alan Stewart, Spring Roo Project Lead

Prince Benin replied on Mon, 2011/11/07 - 3:55pm

Hi Lajos,

I got following error when i want to deploy my application:

roo> cloud foundry deploy --appName rooException in thread "Spring Roo JLine Shell" java.lang.ClassCastException: java.lang.String cannot be cast to
        at jline.ConsoleReader.complete(
        at jline.ConsoleReader.readLine(
        at jline.ConsoleReader.readLine(
        at jline.ConsoleReader.readLine(
        at Source)

 Can you help me please?


Paap Joop replied on Mon, 2011/12/12 - 5:46am

Hi Lajos, nice blog

when i execute "mvn package ....." , i get error that could not resolve dependencies with annotations.jar  which i have installed by mvn install:install-file -DgroupId=org.springframework.roo -DartifactId=org.springframework.roo.annotations -Dversion=1.2.0.BUILD-SNAPSHOT -Dpackaging=jar -Dfile=spring-roo-1.2.0.BUILD-SNAPSHOT/annotations/org.springframework.roo.annotations-1.2.0.BUILD-SNAPSHOT.jar

Thank you in advance.

Paap Joop replied on Mon, 2011/12/12 - 6:48am in response to: Paap Joop

it's working now! i've done error when installing annotations. i did'nt specify the good path -Dfile=d:/spring-roo-1.2.0.BUILD-SNAPSHOT/annotations.


Hadrien Boye replied on Tue, 2011/12/20 - 5:14am

Hi, thankyou for this great article which makes concrete spring roo come blazing fast !

i tried to deloy my app on cloud foundry (, and i get this error when i try accessing a list or create page :


javax.servlet.ServletException: Failed to parse the expression [#{applicationBean.getColumnName(column)}]

root cause

javax.el.ELException: Failed to parse the expression [#{applicationBean.getColumnName(column)}]


 is it something related to JSF version supported by cloud foundry ? any hint ?

edit :  potential answer : support of passing arguments to methods call in Expression Language was introduced in JSP 2.2. Which is not suported by Tomcat before v7... (Cloud foundry runs Tomcat 6).

 > wich container do you use for ?

Balasubramanian... replied on Wed, 2011/12/21 - 3:52pm

I do not like to generate my gui from managed bean, i prefer to use xhtml only. How i do remove generating gui code in managed bean

Anabelle Trinidad replied on Tue, 2011/12/27 - 8:45pm

Hi Lajos..great article. Just wanna ask, how were you able to add the theme switcher in the footer? I'm using SPRING ROO 1.2.0.RC1. thanks!

Rudi Gruteke replied on Sat, 2012/01/07 - 2:57am in response to: Hadrien Boye

I tried with roo 1.2 GA. Exactly the same problem. It works on Tomcat 7.0.23 as local install, but not on Tomcat 6.0.35 local and not in cloud foundry. Is there any bypass?

Carla Brian replied on Thu, 2012/06/14 - 6:10pm

This is nice. I think this is a good software. I will install this application now. - Joe Aldeguer

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.