I am trying to use spring to provide managed beans jsf. I assume that @ManagedBean will be captured by the JSF container to bind EL in JSF with a managed bean, even when I use spring by setting the use of spring in faces-config.xml.
Spring should provide beans, but now , which manages the beans scope?
I tried the following annotation on beans so that it becomes a request scope, but they do not work.
@ManagedBean(name="helloBean")
@RequestScoped
@Scope(value="request")
@Controller
public class HelloBean implements Serializable {
In fact, I used to use simple JSFs, while @ManagedBean and @RequestScoped worked well. Now that I tried to integrate using spring, the scope is not working.
I even tried setting the bean scope to spring configuration, but they work as expected in the spring context (singleton and prototype), but not in the context of the web request.
I tried to avoid using the above @Scope and @Controller annotation, hoping that JSF would manage the scope, but not look.
Below are the file fragments for spring config and MyHelloBean, which are likely to help you communicate better.
<bean id="helloBean" class="com.mkyong.common.HelloBean" init-method="init" />
<bean id="myHelloBean" class="com.mkyong.common.MyHelloBean" init-method="init" >
<property name="helloBean" ref="helloBean"></property>
</bean>
@ManagedBean
@RequestScoped
@Scope(value="request")
@Controller
public class MyHelloBean implements Serializable {
private static final long serialVersionUID = 1L;
private HelloBean helloBean;
see above MyHelloBean I use spring DI to install helloBean, which installs with spring in order. I commented on @ManagedBean, which I think I can leave it there, as it will be ignored by spring by any means, and the JSF is not going to handle it. I suppose, but to be safe, I commented on this so that the JSF doesn't process it.
, faces-config spring.
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
,
Miten.