JSF-centric integration
To achieve JSF-centric way of integration, there are two approaches as detailed below:
- Using DelegatingVariableResolver
- Using FacesContextUtils
We will now discuss these two approaches in detail in the following sections.
Using DelegatingVariableResolver
The class DelegatingVariableResolver resides in package org.springframework.web.jsf package. In this approach Spring Framework plugs in as a JSF managed bean provider. First define JSF beans in faces-config.xml as managed beans and refer to the spring beans using the managed-property configuration as shown in Listing 13-4 below.
Listing 13-4. Spring beans declared as managed bean provider
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<managed-bean> <managed-bean-name>loyaltyService</managed-bean-name> <managed-bean-class>com.apress.loyalty.service.LoyaltyService</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> <managed-property> <property-name>customerRepository</property-name> <property-class>com.apress.loyalty.CustomerRepository</property-class> <value>#{customerRepository}</value> </managed-property> </managed-bean> |
For using the beans managed by the Spring container in different places of your JSF application you can use Spring’s DelegatingVariableResolver to resolve the managed property from Spring application context and then JSF’s IoC injects the bean to the JSF managed bean instance. The DelegatingVariableResolver is declared in faces-confog.xml as shown in Listing 13-5 below.
Listing 13-5. Declaring DelegatingVariableResolver in faces-config.xml
1 2 3 4 5 6 7 8 |
<application> <variable-resolver> org.springframework.web.jsf.DelegatingVariableResolver </variable-resolver>; </application> |
After this, you will have to define the bean in the Spring configuration file as shown in Listing 13-6 below.
Listing 13-6. Declaring Spring managed bean in Spring configuration file
1 2 3 4 5 6 7 8 9 10 11 12 13 |
… <beans default-autowire="no" default-lazy-init="false" default-dependency-check="none"> <bean id="customerRepository"> … </bean> </beans> … |
Pictorially this approach using DelegatingVariableResolver using JSF IoC and Spring IoC is as shown in Figure 13-6 below.
Figure 13-6. JSF-centric integration
Page Visitors: 3795

Tomcy John

Latest posts by Tomcy John (see all)
- A Guide to Continuous Improvement for Architects - February 2, 2023
- Cloud-first Architecture Strategy - January 26, 2023
- Architecture Strategy and how to create One - January 24, 2023
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. . . . . .