DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Coding
  3. Frameworks
  4. JSF 2.0 with Spring Roo

JSF 2.0 with Spring Roo

Lajos Papp user avatar by
Lajos Papp
·
Nov. 01, 11 · Interview
Like (0)
Save
Tweet
Share
32.20K Views

Join the DZone community and get the full member experience.

Join For Free

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
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 Spring Framework

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • 5 Steps for Getting Started in Deep Learning
  • Building a Real-Time App With Spring Boot, Cassandra, Pulsar, React, and Hilla
  • Journey to Event Driven, Part 1: Why Event-First Programming Changes Everything
  • Microservices 101: Transactional Outbox and Inbox

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: