|
Spring Framework example source code file (SpringBeanFacesELResolver.java)
This example Spring Framework source code file (SpringBeanFacesELResolver.java) is included in the DevDaily.com
"Java Source Code
Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.
The Spring Framework SpringBeanFacesELResolver.java source code
/*
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.jsf.el;
import javax.el.ELContext;
import javax.faces.context.FacesContext;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.access.el.SpringBeanELResolver;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.jsf.FacesContextUtils;
/**
* JSF 1.2 <code>ELResolver that delegates to the Spring root
* <code>WebApplicationContext, resolving name references to
* Spring-defined beans.
*
* <p>Configure this resolver in your faces-config.xml file as follows:
*
* <pre>
* <application>
* ...
* <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
* </application></pre>
*
* All your JSF expressions can then implicitly refer to the names of
* Spring-managed service layer beans, for example in property values of
* JSF-managed beans:
*
* <pre>
* <managed-bean>
* <managed-bean-name>myJsfManagedBean</managed-bean-name>
* <managed-bean-class>example.MyJsfManagedBean</managed-bean-class>
* <managed-bean-scope>session</managed-bean-scope>
* <managed-property>
* <property-name>mySpringManagedBusinessObject</property-name>
* <value>#{mySpringManagedBusinessObject}</value>
* </managed-property>
* </managed-bean></pre>
*
* with "mySpringManagedBusinessObject" defined as Spring bean in
* applicationContext.xml:
*
* <pre>
* <bean id="mySpringManagedBusinessObject" class="example.MySpringManagedBusinessObject">
* ...
* </bean></pre>
*
* @author Juergen Hoeller
* @since 2.5
* @see WebApplicationContextFacesELResolver
* @see org.springframework.web.jsf.FacesContextUtils#getRequiredWebApplicationContext
*/
public class SpringBeanFacesELResolver extends SpringBeanELResolver {
/**
* This implementation delegates to {@link #getWebApplicationContext}.
* Can be overridden to provide an arbitrary BeanFactory reference to resolve
* against; usually, this will be a full Spring ApplicationContext.
* @param elContext the current JSF ELContext
* @return the Spring BeanFactory (never <code>null)
*/
protected BeanFactory getBeanFactory(ELContext elContext) {
return getWebApplicationContext(elContext);
}
/**
* Retrieve the web application context to delegate bean name resolution to.
* <p>The default implementation delegates to FacesContextUtils.
* @param elContext the current JSF ELContext
* @return the Spring web application context (never <code>null)
* @see org.springframework.web.jsf.FacesContextUtils#getRequiredWebApplicationContext
*/
protected WebApplicationContext getWebApplicationContext(ELContext elContext) {
FacesContext facesContext = FacesContext.getCurrentInstance();
return FacesContextUtils.getRequiredWebApplicationContext(facesContext);
}
}
Other Spring Framework examples (source code examples)
Here is a short list of links related to this Spring Framework SpringBeanFacesELResolver.java source code file:
|