Spring Book – Chapter 13 – Spring and JSF Integration

In addition to DelegatingVariableResolver, Spring provides two more resolvers which can be configured and used taking into considering application requirement and its merits. They are:

  • org.springframework.web.jsf.SpringBeanVariableResolver – This is a subclass of the JSF 1.1 DelegatingVariableResolver, letting Spring bean definitions override other attributes of the same name. It delegates to the Spring’s “business context” WebApplicationContext first and then to the default resolver of the underlying JSF implementation. This is useful when using request/session-scoped beans with special Spring resolution rules, e.g. Spring FactoryBean implementations. Listing 13-7 below shows declaring this resolver in faces-config.xml file.

Listing 13-7. Declaring SpringBeanVariableResolver in faces-config.xml file

  • org.springframework.web.jsf.el.SpringBeanFacesELResolver – JSF 1.2 ELResolver that delegates to the Spring root WebApplicationContext, resolving name references to Spring-defined beans. Listing 13-8 below shows configuring SpringBeanFacesELResolver in faces-config.xml file.

Listing 13-8. Configuring SpringBeanFacesELResolver in faces-config.xml file

Using FacesContextUtils

FacesContextUtils is an utility class that is located in Spring Framework in org.springframework.web.jsf package. Beans declared as Spring managed beans can be retrieved in any part of your application code in JSF as shown in Listing 13-9 below.

Listing 13-9. Getting bean declared in Spring and using in JSF application

Whether you select Spring-centric or JSF-centric way of integration, the complete integration between Spring and JSF can be pictorially represented as shown in Figure 13-7 below.


Figure 13-7. Integration between Spring and JSF

Spring and JSF with WebFlow

I wouldn’t go into detail of this section but I wouldn’t want you to be completely unaware of this integration as this is very important and useful in case of certain UI requirement which you can encounter in your web application development. The following Chapter 14 discusses Spring MVC along with Spring WebFlow in detail. Suring that time you can keep in mind of Spring and JSF with WebFlow integration and look into possible use in your application as the case may be.

The decision whether to use WebFlow as discussed in earlier paragraph is completely based on your UI requirements. If Spring and JSF is already in use the only reason that I see using WebFlow is when your application has more wizard like UI forms whose plumbing could be more elegantly handled by Spring WebFlow rather than JSF faces-context navigation rules, which over a period of time could be complex and hard to maintain.

The integration of Spring and JSF with WebFlow also vary between different JSF implementation available in market as well as JSF version that you are trying to integrate with.

If you do not have heavy wizard-specific views in your application, using Spring WebFlow will be more of a pain rather than a remedy and I would suggest avoiding this usage. To use Spring WebFlow follow the following easy steps as summarized below:

  • Register the resolver in your faces-confog.xml file.
  • Mark your controller classes with appropriate stereotype e.g. @Controller with desired scope.
  • Get references to Spring-managed beans via manual- or autowiring.

Spring Faces

We are almost nearing the end of this Chapter and you might be wondering how I can wait all this while to introduce you to this section. I wanted to just skim through this as I wouldn’t be able to go deep into this section. But as mentioned multiple times throughout this book, I wouldn’t want you to read through this entire Chapter and not know when someone asks you “What is Spring Faces?”, so here is the answer to it:

Spring Faces is Spring’s JSF integration module.  The module ships with the Spring Web Flow 2.0 distribution.  It provides support for Web Flow in a JSF environment, as well as a lightweight component library for progressive Ajax built on Spring Javascript.

–          www.springsource.org

In the next Chapter (Chapter 14), I will explain this in detail so that you have a better understanding of this so that you can address the question asked earlier in an authoritative manner.


Spring Framework with its inherent capability of pluggability allows plugging in external components and frameworks with ease. I this Chapter we saw how easy is it to plug Spring Framework with one of the well know web application standard namely JSF.

The Chapter started off by introducing you to the core concepts and details of JSF as a specification and then delved deep into how you can plug Spring and JSF in your application by using Spring-centric and JSF-centric approaches.

After going through this Chapter you should have got a clear picture of the integration points between the two frameworks. I hope I have been able to cover the main aim of this Chapter and I feel that you would have got good amount of background on JSF as well.

Page Visitors: 3614

The following two tabs change content below.
Tomcy John

Tomcy John

Blogger & Author at javacodebook
He is an Enterprise Java Specialist holding a degree in Engineering (B-Tech) with over 10 years of experience in several industries. He's currently working as Principal Architect at Emirates Group IT since 2005. Prior to this he has worked with Oracle Corporation and Ernst & Young. His main specialization is on various web technologies and acts as chief mentor and Architect to facilitate incorporating Spring as Corporate Standard in the organization.

1 thought on “Spring Book – Chapter 13 – Spring and JSF Integration

  1. Hey very cool blog!! Man .. Excellent .. Wonderful .. I will bookmark your blog and take the feeds also?I’m happy to find a lot of helpful info right here in the put up, we need develop extra techniques in this regard, thank you for sharing. . . . . .

Leave a Reply

Your email address will not be published. Required fields are marked *