In my Java EE 6-webapp (running on latest GlassFish 3.1), I\'m using JSF2-ManagedBeans and @ManagedProperty
to inject them into other ManagedBeans. Now i would
Using @ManagedProperty
in a servlet is not possible since this works in @ManagedBean
classes only. Further, injecting an object which has a lesser scope than the parent itself is also not possible since that would also only end up in concurrency problems. The injector would throw a runtimeexception for that. A servlet is in essence application scoped and shared among all users and your UserIdentity
bean seems to be session scoped.
Since JSF runs on top of the Servlet API and stores the session scoped beans in, well, the session, you could in the servlet just grab it as session attribute:
UserIdentity identity = (UserIdentity) request.getSession().getAttribute("userIdentity");
Note that the FacesContext
is usually also not available in a servlet other than FacesServlet
, so using FacesContext
in the servlet as suggested in a comment does not make any sense, that would only return null
.