Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

jsf spring integration approaches

Posted on 2011-09-06
3
Medium Priority
?
554 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 47

Accepted Solution

by:
for_yan earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

636 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