Solved

jsf spring integration approaches

Posted on 2011-09-06
3
532 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 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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

695 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