No, both ways of declaring the bean should work. Seems like there is something wrong with your setup. Are you using the correct @RequestScoped? There is a CDI and a JSF version of that annotation. And does invoking action methods on that bean work when clicking a h:commandButton or something like that?
BTW: It is very uncommon to migrate from CDI to JSF annotations. The @ManagedBean annotation was a very bad idea and I recommend everyone to move to CDI managed beans instead. So why are you migrating from CDI to JSF annotations?
Actually, I am not trying to migrate. I am just playing with different combinations. Thank you for your help.
Since we touched the topic, I do have 1 question if you don’t mind. It is regarding the @RequestScope and @Scope(“request”)
I am using JSF 2 + Spring framework. It seems like the @RequestScoped does not work as a new bean per request. I have to end up using Spring annotation @Scope(“request”). However in the Spring world, there is no view scope thing which can be useful in Ajax. My question sould be if it is right approach to go with all Spring scope annotation if spring is the selected IOC?
The annotation you have to use to specify the scope of a bean depends on IoC container you are using to manage the bean. As the IoC container is responsible to manage the lifecycle of the bean instances, you must of cause use an annotation that the container understands.
* If you are using plain JSF and @ManagedBean, you have to choose JSF’s @RequestScoped.
* If you are using CDI with JSF, you have to use @Named and CDI’s @RequestScope (different package than the corresponding JSF annotation).
* If you are using JSF with Spring (as in your case), you have to use something like @Component and @Scope(“something”).
So it is correct that @RequestScoped doesn’t work for Spring beans.
There are typically ways to simulate the view scope with other IoC containers. With CDI for example you could use Seam Faces or MyFaces CODI which both provide an implementation of @ViewScoped.
I don’t know what the common pattern is to use the view scope in Spring applications. But there was a blog post by Cagatay Civici some time ago regarding this: