JBoss RichFaces with Spring
This article is going to show you how to build a RichFaces application with Spring. We are going to replace the standard JSF managed beans with Spring beans. We will first use an XML-based configuration approach and then switch to an annotations approach in Spring.
(Note - The Project Template for this article can be downloaded here)
If you want first to try RichFaces with standard JSF managed beans, no problem. Start with this article.
To make it possible to create the application in just under an hour, we are not going to persist any data into a database. To keep things simple, we will keep the data in memory. Of course it's not very difficult to add a persistence layer to this application. Spring provides many tools to do that.
Finally an article on how to use RichFaces with Spring Web Flow, is something that I'm saving for a future article.
What Are We Going to Build?
A pretty common request that I hear is how do you build a wizard in RichFaces. So, that's exactly what we are going to build. You come into a bar and on each table there is a screen via which you place an order. You click to start an order, a wizard is launched where you enter all the required information and place the order. We will also have the ability to view all placed orders. Additionally, we will be able to change the look and feel of the ordering screen using RichFaces’ skinnability feature.
Note: All screen shots show a custom skin which you are going to create later.


JBoss RichFaces
JBoss RichFaces is a framework that consists of three main parts: AJAX (rich) enabled JSF components, skinnability, and CDK (Component Development Kit). RichFaces UI components are divided into two tag libraries a4j: and rich:. Both tag libraries offer out-of-the-box AJAX enabled JSF components. Skinnability enables you to skin a JSF application with default or custom skins (themes). Finally, the CDK is a facility for creating, generating and testing rich JSF components.
RichFaces is not a JSF implementation. RichFaces UI components are just extra AJAX JSF components that work with any JSF implementation (1.1, 1.2, 2.0), any view technology (Facelets, JSP), and are integrated with 3rd party components (MyFaces, Tomahawk, Trinidad, etc).
| Attachment | Size |
|---|---|
| richfaces-spring-wizard.zip | 11.15 MB |
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)











Comments
Aleksandar Vidakovic replied on Mon, 2009/02/16 - 6:04pm
Salut Max,
interesting article. I've been experimenting with Richfaces and Spring for a while and would be extremely interested in the SpringWebflow integration...
Cheers,
Aleks
wismax replied on Tue, 2009/02/17 - 9:57am
Hello Max,
I'm trying to build my richbar application but when I click on the next button of the first wizard page, nothing happens. So I'd like to check your project but I can't find any link in your article. Where can I download your project files ?
Thanks !
Wis
Nitin Bharti replied on Tue, 2009/02/17 - 10:19am
in response to: wismax
Hi Wis,
I believe you can download the project template from here -- http://drop.io/usoalrd
I will add this to the main article as well. Sorry about that.
Thanks,
Nitin
Gene De Lisa replied on Wed, 2009/02/25 - 9:08am
"In the “real” world, you would probably use Maven 2, but, to keep things simple and concentrate on RichFaces and Spring, we are going to use a ready-made project."
maven projects are "ready-made" and they don't have the disadvantages of the approach you have taken.
Other than that this is nothing more a mediocre do this do that tutorial.
Omar Palomino S... replied on Sun, 2009/03/08 - 10:28pm
in response to: vidakovic
Hi Max and Aleksandar,
I'm also interesting in Spring Webflow integration [navigation rules are cumbersome :s]. I have a couple of implementations with both RichFaces, Spring and Jpa, and it's fun and easy to develop this way. Webflow would be a nice addition to this project acthitecture.
taod replied on Fri, 2009/03/13 - 2:34pm
Excellent Article. In case someone want to try it through Maven. Hope the following dependecy setting will save you some time.
<dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-ui</artifactId>
<version>3.3.0.GA</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.richfaces.framework</groupId>
<artifactId>richfaces-api</artifactId>
<version>3.3.0.GA</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.richfaces.framework</groupId>
<artifactId>richfaces-impl</artifactId>
<version>3.3.0.GA</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.richfaces.samples</groupId>
<artifactId>laguna</artifactId>
<version>3.3.0.GA</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.8.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
<version>2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
<scope>compile</scope>
</dependency>
<!-- JBoss RichFaces Repository -->
<repository>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
<id>repository.jboss.com</id>
<name>Jboss Repository for Maven</name>
<url>
http://repository.jboss.com/maven2/
</url>
<layout>default</layout>
</repository>
maxkatz replied on Mon, 2009/03/16 - 10:53am
in response to: taod
salemba replied on Tue, 2009/03/17 - 6:44pm
First, thanks for the great work :)
but
<cite> (Note - The Project Template for this article can be downloaded from http://drop.io/usoalrd) </cite>
what is the pass for download ?
thanks in advance!
ander.santos replied on Wed, 2009/03/18 - 9:28am
Hi Buddy,
This article is just great, I have been looking for a steb by step like this one, for at least a month.
I just couldn't download the template for this project, could you please send it by e-mail to me, that link where you say to click for download is broken and the one in the first page os this article, I just couldn't use...
thanks,
Anderson
ander.dev@gmail.com
JeanChastain replied on Wed, 2009/03/18 - 4:27pm
samset replied on Sat, 2009/03/21 - 12:01pm
in response to: JeanChastain
hi, it's been quite some time i am trying to make richfaces 3.3 work with spring 2.0 webflow. Can somebody tell me how to download the source code. I visited http://drop.io/usoalrd, it's asking for password. What am i suppose to enter there ?
or, can you send me through email ?
Appreciate your help!
aseem.monga replied on Tue, 2009/03/31 - 7:59am
juanjogoa24 replied on Wed, 2009/04/01 - 7:03pm
thanks
juanjogoa24@gmail.com
.
maxkatz replied on Sat, 2009/04/11 - 11:47am
davutuysal replied on Fri, 2009/04/17 - 9:48am
shan2856 replied on Sat, 2009/04/25 - 1:36am
Donovan Makund replied on Sun, 2009/04/26 - 3:11pm
in response to: maxkatz
shan2856 replied on Thu, 2009/04/30 - 1:57am
maxkatz replied on Tue, 2009/05/05 - 1:45pm
Let's try this file. Here is what you need to do:
Download the template.
In Eclipse:
shan2856 replied on Thu, 2009/05/07 - 8:08am
maxkatz replied on Tue, 2009/05/19 - 6:05pm
in response to: shan2856
Donovan Makund replied on Sat, 2009/06/06 - 11:48am
maxkatz replied on Fri, 2009/06/12 - 11:18am
in response to: dmakund
atmohsin replied on Tue, 2009/06/16 - 2:30pm
martinhaas replied on Mon, 2009/06/22 - 5:50am
maxkatz replied on Mon, 2009/06/22 - 3:26pm
in response to: atmohsin
maxkatz replied on Mon, 2009/06/22 - 3:29pm
in response to: martinhaas
stuba999 replied on Thu, 2009/07/16 - 10:26am
Hi Max,
Firstly thanks for this article it's good to have a straigthforward example of using these frameworks together.
I do have a problem running this on a was 6.1 instance. (However I don't think this is the issue here). I've placed the code into an existing webb app project to prove the spring framework can run in an existing richfaces / facelets implementation
My stack trace on requesting http://localhost:9080/MyProjectName/start.jsf is as follows
Do you have any idea why I'm getting a NotSerializeableException thrown when trying to instantiate this bean? (presumeably through Spring DI ?(I'm a newbie when it comes to jsf and spring))
Thanks
Stuart
maxkatz replied on Thu, 2009/07/16 - 10:47am
stuba999 replied on Thu, 2009/07/16 - 11:00am
in response to: maxkatz
Thanks Max.
I thought that might (and did) do the trick. As a newbie just wondered if the stack trace might shed any light on why the exception was throwing.
Keep the articles coming . Thanks again
Stuart