JSF 2.0 with Spring Roo
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: http://roojsfpreview.cloudfoundry.com/ (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: http://static.springsource.org/downloads/nightly/snapshot-download.php?project=ROO
unzip /path/to/spring-roo-1.2.0.BUILD-SNAPSHOT_201110XX.XXXXXXXXXXX.zip
ROO_HOME=$(readlink -f spring-roo-1.2.0.BUILD-SNAPSHOT)
PATH=$ROO_HOME/bin:$PATH
roo.sh
____ ____ ____
/ __ \/ __ \/ __ \
/ /_/ / / / / / / /
/ _, _/ /_/ / /_/ /
/_/ |_|\____/\____/ 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 quit
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=http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.22/bin/apache-tomcat-7.0.22.zip ... [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 yourname@gmail.com --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
Keep up with the good work Alan Steward and the entire Spring Roo Team!
| Attachment | Size |
|---|---|
| spring-roo-jsf-webapp-small.png | 48.71 KB |
| spring-roo-jsf-webapp.png | 85.95 KB |
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)





Comments
Mac Luq replied on Wed, 2011/11/02 - 3:04am
Ennius replied on Wed, 2011/11/02 - 5:10am
Charlie Mordant replied on Wed, 2011/11/02 - 5:28am
Lajos Papp replied on Wed, 2011/11/02 - 8:54am
in response to:
Ennius
Ali2 Ebrahimi replied on Wed, 2011/11/02 - 10:06am
Ansar Basha replied on Wed, 2011/11/02 - 10:30am
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
Lajos Papp replied on Thu, 2011/11/03 - 3:07am
in response to:
Lajos Papp
Lajos Papp replied on Thu, 2011/11/03 - 4:22am
in response to:
Lajos Papp
Roger Itai replied on Thu, 2011/11/03 - 2:03pm
Hi,
I got following error when ran Maven:
[ERROR] Failed to execute goal on project telepizza: Could not resolve dependenc
ies for project br.com.alvorada.telepizza:telepizza:war:0.1.0.BUILD-SNAPSHOT: Fa
ilure to find org.springframework.roo:org.springframework.roo.annotations:jar:1.
2.0.BUILD-SNAPSHOT in http://maven.springframework.org/release 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
Alan Stewart replied on Fri, 2011/11/04 - 6:57pm
Cheers
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 org.springframework.roo.shell.Completion at org.springframework.roo.shell.SimpleParser.complete(SimpleParser.java:694) at org.springframework.roo.shell.jline.JLineCompletorAdapter.complete(JLineCompletorAdapter.java:35) at jline.ConsoleReader.complete(ConsoleReader.java:936) at jline.ConsoleReader.readLine(ConsoleReader.java:603) at jline.ConsoleReader.readLine(ConsoleReader.java:457) at jline.ConsoleReader.readLine(ConsoleReader.java:283) at org.springframework.roo.shell.jline.JLineShell.promptLoop(JLineShell.java:395) at org.springframework.roo.shell.jline.JLineShell.run(JLineShell.java:158) at java.lang.Thread.run(Unknown 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.
thanks
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 (http://organstore.cloudfoundry.com), and i get this error when i try accessing a list or create page :
exception
javax.servlet.ServletException: Failed to parse the expression [#{applicationBean.getColumnName(column)}] javax.faces.webapp.FacesServlet.service(FacesServlet.java:229) org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79) org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:147) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)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 http://roojsfpreview.cloudfoundry.com/ ?
Balasubramanian... replied on Wed, 2011/12/21 - 3:52pm
Anabelle Trinidad replied on Tue, 2011/12/27 - 8:45pm
Rudi Gruteke replied on Sat, 2012/01/07 - 2:57am
in response to:
Hadrien Boye
Carla Brian replied on Thu, 2012/06/14 - 6:10pm