JSF and Spring
Coming straight to integration approaches, there are two approaches possible as below:
- Spring-centric integration
- JSF-centric integration
Spring-centric integration
With latest release of Spring (later than Spring version 2.x), Spring Framework has a capability of handling JSF backing beans in its IoC container avoiding JSF IoC container in all aspects and making using of strong Spring IoC for managing beans in a JSF application. By using this you can completely avoid putting the bean declaration in the faces-config.xml file and use the Spring configuration file instead. The following steps needs to be done to achieve this Spring-centric approach:
- Declare the DelegatingVariableReslver in the faces-config.xml file as shown in Listing 13-1 below.
Listing 13-1. Declaring DelegatingVariableResolver in faces-config.xml file
1 2 3 4 5 6 7 8 9 10 11 12 13 |
… <application> <variable-resolver> org.springframework.web.jsf.DelegatingVariableResolver </variable-resolver> </application> … |
- Declare your backing bean as well as Spring bean in the Spring configuration file as shown in Listing 13-2 below.
Listing 13-2. Declaring backing bean and Spring bean in Spring configuration file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
… <!-- Spring Bean --> <bean id="loyaltyService"></bean> <!-- Backing bean using Spring bean as reference --> <bean id="saveCustomerBean" scope="request"> <property name="loyaltyService"> <ref bean="loyaltyService"/> </property> </bean> … |
- Declaring appropriate listeners in the web application context file web.xml as shown in Listing 13-3 below.
Listing 13-3. Configuring listeners in the web.xml file of your JSF application
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
… <!-- Spring configuration file declartion --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <listener> <listener-class> org.springframework.web.context.request.RequestContextListener <listener-class> </listener> … |
Pictorially this Spring-centric approach can be depicted as shown in Figure 13-5 below.
Figure 13-5. Spring-centric integration
This approach is referred from a blog entry written in the following URL which seemed very logical; http://cagataycivici.wordpress.com/2007/09/10/using-spring-to-manage-jsf-beans/. You can have a complete working sample of this approach in this blog entry.
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. . . . . .