haju
haju

Reputation: 1298

Spring beans injected into JSF Managed Beans

Problem Description: My injected Spring bean defined as a Managed-Property to a JSF backing bean is not being instantiated. Its always coming up null when I retreive the Managed-Bean.

I have been fighting with this all day and it seems that JSF Managed Bean just won't read out of the applicationContext from Spring. I can manually pull out the bean by using the FacesContext in a backing bean and it finds the bean but when I try and inject it through the FacesConfig it always comes out null. I included my steps below how I integrated it. Any suggestions?

Configuration

Icefaces 1.85

JSF 1.2 (through ice faces servlet)

Spring 3.0

Websphere 7.5 ( Which is eclipse 3.5 I think )

Web.xml Configuration Changes

Spring Context Loader Listener

    <listener>
    <display-name>SpringListener</display-name>
    <icon>
        <small-icon>small.gif</small-icon>
        <large-icon>large.gif</large-icon>
    </icon>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

Context Config

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/SpringConfig/SpringHelloWorld.xml
    </param-value> 
</context-param>

FacesContext Changes

Variable Resolver - AKA The Glue

<application><variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver></application>

Managed Bean

   <managed-bean>
    <managed-bean-name>testData</managed-bean-name>
    <managed-bean-class>src.test.TestData</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    <managed-property>
        <property-name>spring3HelloWorldBean</property-name>
        <value>#{spring3HelloWorldBean}</value>
    </managed-property>
</managed-bean>

Spring.xml Config

<bean id="spring3HelloWorldBean" class="src.test.Spring3HelloWorld" />

Thanks in advance

Upvotes: 2

Views: 9877

Answers (2)

danny.lesnik
danny.lesnik

Reputation: 18639

First of all and I think this your problem that DelegatingVariableResolver is deprecated in all JSF version after 1.1 and you are using 1.2 so please use this following configuration.

<application> 
<el-resolver> 
org.springframework.web.jsf.el.SpringBeanFacesELResolver 
</el-resolver> 
</application>

Hope it helps.

Upvotes: 12

Bozho
Bozho

Reputation: 597016

In addition to using SpringBeanFacesELResolver you can benefit even more from spring by using annotations. So instead of defining your managed bean in xml, just do:

@Controller
public class FooBean {
    @Inject
    private SpringService service;
    ....
}

Upvotes: 4

Related Questions