I have a @RequestScoped
bean with a List
property.
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
imp
You shouldn't manage a single bean by multiple different bean management frameworks like JSF, CDI and Spring. Choose the one or the other. When managing the bean by for example Spring's @Controller
, all bean management related annotations of other frameworks like JSF's @ManagedBean
and CDI's @Named
are ignored.
I don't do Spring and I have no idea why you're using it instead of the standard Java EE 6 API, but the symptoms and documentation indicates that the scope of such a Spring bean indeed defaults to the application scope. You need to specify the bean scope by Spring @Scope
annotation. You would also like to remove the JSF bean management annotations since they have no value anymore anyway and would only confuse the developer/maintainer.
@Controller
@Scope("request")
public class MyBean implements Serializable {
// ...
}
Alternatively, you can also get rid of Spring @Controller
annotation and stick to JSF @ManagedBean
. You can use @ManagedProperty
instead of @Autowired
to inject another @ManagedBean
instance or even a Spring managed bean (if you have Spring Faces EL resolver configured), or the Java EE standard @EJB
to inject an @Stateless
or @Stateful
instance.
E.g.
@ManagedBean
@RequestScoped
public class MyBean implements Serializable {
@EJB
private SomeService service;
// ...
}