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
Gene De Lisa replied on Fri, 2009/07/31 - 9:45am
What exactly are you thinking by posting an 11 MB zip file that contains nothing but library jar files? Are you getting some perverse pleasure by wasting other people's time and bandwidth? Do you know the meaning of the word courtesy? Apparently not.
If you don't want to post your code don't post a zip. It's as simple as that.
Kushan Jayathilake replied on Fri, 2009/10/30 - 7:56am
Hi Max, Great work!..
i have a problem, i have added the validation conditions in managed bean of the JSF page
ie :
i have several <a4j:commandButton> and <a4j:commandLink> in the same page, validation fires each and every time i press a commandLink or Button, iif that field is empty("countryName" as i specified here)
how can i control the validation to fire for the particular button or a link...? (i need validation to be fired when only i clicked the save button)
please help me on this...
Max Katz replied on Thu, 2009/11/05 - 8:10pm
in response to:
Kushan Jayathilake
Kushan Jayathilake replied on Fri, 2009/11/06 - 6:45am
I have another question,
I want to generate dynamic checkboxes depends on a collection, so i have written
<h:dataTable id="functionsGrid" value="# {functionManagedBean.collecOfFunctions}" var="function" > <h:column> <h:selectBooleanCheckbox id="#{function.functionName}" value="#{functionManagedBean.checked}"/> <h:outputLabel for="" value="outputLabel"></h:outputLabel> </h:column> </h:dataTable>and finally this form contains an <a4j:commandButton> , in the managedBean side i want to get the selected checkboxes....(problem is checkboxes are generating dyamically, so how can assign their values for the different properties in the managedBean..
Thank you very much in advance.. :)
Tee Siong replied on Wed, 2010/04/07 - 5:40am
Thomas Strecker replied on Thu, 2010/05/27 - 3:36am
in response to:
Mohsin Khan
I encountered the same problem, but only after switching to Spring Annotations and Component Scan. The reason is rather simple: the WizardBean now no longer receives the value for the startPage (which was set to "/page1.xhtml" in the spring application context before) and now the renderer ends up in a endless loop.
So if you want to use the annotation based version, manually set the parameter in the bean.
Mohammad Shariq replied on Tue, 2010/06/15 - 2:50pm
Mehdi Ben Haj Abbes replied on Mon, 2010/07/19 - 2:18am
in response to:
stu bilton
Fabio Malheiro replied on Tue, 2010/09/28 - 8:26am
This was supposed to be a good tutorial right?
I was trying to implement your example... but I'm a little bit confused. Sometimes you "talk" about a bean orderService, and Service ... but where the fuck is the Service class?
Andres Botero replied on Wed, 2010/11/17 - 12:02pm
When i inyect a dependency into a bean it's null. For Example:
<bean id="wizardBean" class="bar.view.WizardBean" scope="request">
<property name="orderService" >
<ref bean="service" />
</property>
</bean>
In that case the orderService is null, colud you tell me why is that?
A S M Russel replied on Fri, 2011/09/30 - 1:10am
After Migrating from XML configuration to Annotation based configurated i am getting the following error.
at com.sun.facelets.el.VariableMapperWrapper.resolveVariable(VariableMapperWrapper.java:60)
the error trace is too long thats why i am pasting it here.
I create the spring3 template project with STS and follow your instruction.
Its working well for xml configuration.But getting error when i am going to annotation based configuration
Scott Duke replied on Tue, 2011/10/25 - 10:46pm
Max Katz replied on Thu, 2011/10/27 - 4:48pm
in response to:
Scott Duke
Nagy Andika replied on Fri, 2011/11/04 - 5:13am