user3121879
user3121879

Reputation: 7

injecting springbean into jsf managed bean?

i put class listners in my WEb.xml

<listener>
<listener-class>org.springframework.web.context.request.
    RequestContextListener</listener-class> 
</listener>

in facesconfig.xml

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

in applicationcontext.xml

<context:component-scan base-package="com.test.jsf" />

and to my managedbean in jsf

package com.test.jsf;

@ManagedBean
@Controller
@Scope(value = "request")
public class page1_backing
{
 @Autowired
 private UserInfo ui;

 ...
 }

but shows warning to add handler. then i put

 <view-handler>com.sun.facelets.FaceletViewHandler</view-handler

but it doesnt let me go smmothe.please help me to accomplish this task.

Upvotes: 0

Views: 86

Answers (1)

bhdrk
bhdrk

Reputation: 3495

Not just RequestContextListener. also add ContextLoaderListener.

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

And only use @Component annotation for managed bean,

package com.test.jsf;

@Component
@Scope(value = "request")
public class page1_backing
{
    @Autowired
    private UserInfo ui;

    ...
}

it should work.

Upvotes: 1

Related Questions