Solved

jsf spring integration approaches

Posted on 2011-09-06
3
516 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
Comment Utility

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
Comment Utility

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

Expert Comment

by:for_yan
Comment Utility

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Increment alphanumeric sequence 6 79
HashMap Vs TreeMap 12 48
JDeveloper 12c for 32 bit 4 34
Java / Linux and Regular Expressions 11 43
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
The viewer will learn how to implement Singleton Design Pattern in Java.

743 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now