Solved

jsf spring integration approaches

Posted on 2011-09-06
3
524 Views
Last Modified: 2012-05-12
I would like to know about various jsf spring integration approaches.
Esp difference between DelegatingVariableResolver, FacesContextUtils:custom VariableResolve approaches. When how why we use each approach. I am not clear in this concept. thanks in advance
0
Comment
Question by:gudii9
  • 2
3 Comments
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 36497850

This is rather special stuff to my mind but you can read about it here:

http://static.springsource.org/spring/docs/2.0.x/reference/webintegration.html

----
15.3. JavaServer Faces

JavaServer Faces (JSF) is an increasingly popular component-based, event-driven web framework. The key class in Spring's JSF integration is the DelegatingVariableResolver class.
15.3.1. DelegatingVariableResolver

The easiest way to integrate one's Spring middle-tier with one's JSF web layer is to use the DelegatingVariableResolver class. To configure this variable resolver in one's application, one will need to edit one's faces-context.xml file. After the opening <faces-config/> element, add an <application/> element and a <variable-resolver/> element within it. The value of the variable resolver should reference Spring's DelegatingVariableResolver; for example:

<faces-config>
  <application>
    <variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>
      <locale-config>
        <default-locale>en</default-locale>
        <supported-locale>en</supported-locale>
        <supported-locale>es</supported-locale>
      </locale-config>
      <message-bundle>messages</message-bundle>
    </application>
</faces-config>

The DelegatingVariableResolver will first delegate value lookups to the default resolver of the underlying JSF implementation, and then to Spring's 'business context' WebApplicationContext. This allows one to easily inject dependencies into one's JSF-managed beans.

Managed beans are defined in one's faces-config.xml file. Find below an example where #{userManager} is a bean that is retrieved from the Spring 'business context'.

<managed-bean>
  <managed-bean-name>userList</managed-bean-name>
      <managed-bean-class>com.whatever.jsf.UserList</managed-bean-class>
  <managed-bean-scope>request</managed-bean-scope>
  <managed-property>
    <property-name>userManager</property-name>
    <value>#{userManager}</value>
  </managed-property>
</managed-bean>

15.3.2. FacesContextUtils

A custom VariableResolver works well when mapping one's properties to beans in faces-config.xml, but at times one may need to grab a bean explicitly. The FacesContextUtils class makes this easy. It is similar to WebApplicationContextUtils, except that it takes a FacesContext parameter rather than a ServletContext parameter.

ApplicationContext ctx = FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance());
----
You can look also a few parapgraphs above about integratuion with ServletContext which is similar




 


There is also JSF-Spring project which allows to have deeper bidirectyional integration
between Spring and JSF - below is the explanation of what additionally JSF-Spring brings
from http://jsf-spring.sourceforge.net/

Spring: link between JSF and Spring

Spring includes a JSF VariableResolver implementation that is aware of Spring-managed beans and thus gives access to those beans by referring to their bean name in JSF expressions. So what it basically does is providing JSF with a link to Spring beans. This solution will be sufficient in many cases.
JSF-Spring: integration of both frameworks

JSF-Spring provides Spring with a WebApplicationContext containing JSF's managed-beans and integrates it into Spring's context hierarchy. Thus it makes Spring beans available to JSF beans and integrates JSF beans into Spring, providing a more comprehensive (bidirectional) integration, including the ability to use Spring's features within JSF beans. Furthermore, you are able to integrate SpringMVC and thus any other action based Web application framework that is integrated by Spring (e.g. Struts etc.). Using JSF-Spring with jsf-facelets you will be able to submit forms via GET and write RESTful web applications with a common JSF stack.

0
 
LVL 7

Author Comment

by:gudii9
ID: 36589885

>>>>WebApplicationContextUtils,FacesContextUtils
 What are their differences, advantages, disadvantage, uses of them
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36589940

WebApplicationContextUtils applies to integration of spting with any java web applications(servlets)

FacesContextUtils come into play when you are integrating with JSF  application
 

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
session migration servlets 2 42
web services creation SOAP vs REST 5 56
jboss wildfly 10.1 10 216
ejb example issues 3 18
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question