I try to declare JSF managed bean with @Named and @javax.faces.view.ViewScoped annotations in a spring 4.1 application on JSF 2.2.10 (Mojarra) but it seems that the managed beans are eagerly loaded that cause some problems. Someone could say me why?
Asked
Active
Viewed 291 times
1
-
possible duplicate of [View-scoped bean recreated on POST with JSF 2.2.4](http://stackoverflow.com/questions/20251176/view-scoped-bean-recreated-on-post-with-jsf-2-2-4) – Kukeltje Feb 25 '15 at 19:07
-
It's not the same topic. the problem I'm facing is that the beans are loaded eagerly which cause some problems.I assume that it's a spring effect but i would to know if someone had this problem – jperf Feb 25 '15 at 19:41
-
It still might be related. If you you a wrong scope that Spring does not recognize, it might default to a scope that is eagerly loaded. Just like jsf (seems to) default to a requestscope if a wrong scope is used – Kukeltje Feb 25 '15 at 19:44
-
If you are using Spring and your JSF beans are also managed by Spring they are now singletons. Spring doesn't know about the `java.faces.view` scopes and ignores them. I would suggest either CDI instead of Spring (or try to get both working together, which isn't a pleasant exercise imho) or use `@ManagedBean` and `@ViewScoped` from the `javax.enterprise` package. – M. Deinum Feb 25 '15 at 20:16
-
@M.Deinum I think you meant `@ManagedBean` and `@ViewScoped` from the `javax.faces` package ;) to avoid mixing CDI with JSF managed beans – Tarik Feb 26 '15 at 01:58
-
The beans.xml file is missing so spring manage beans and doesn't recognize @javax.faces.view.ViewScoped annotations (ignore it) and consider the singleton scope which is the default spring scope. Moveing the entire application to CDI is not an option for the moment. Thanks. – jperf Feb 26 '15 at 08:07
-
@Tarik you are right the ones from the `javax.faces.bean` package are the one. – M. Deinum Feb 28 '15 at 13:01