0

Here is the managed bean declaration:

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean(name = "user")
@SessionScoped
public class UserConsoleAction extends UserAction implements Serializable {

And the following code from servlet returns null:

UserConsoleAction uca =  (UserConsoleAction) req.getSession().getAttribute("user");

This is an old code written on JSF 1 and now JSF 2.2 is using. This was working fine & able to get session scoped managed bean from session when managed bean was declared in faces-config.xml.

<managed-bean>
    <description>Used for user console functions</description>
    <managed-bean-name>user</managed-bean-name>
    <managed-bean-class>com.web.admin.UserConsoleAction</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
</managed-bean>

But when I removed this faces-config.xml entry & used ManagedBean annotation, the code to get managed bean instance from session returns null. What may be the cause for this change since it is only the declaration part changed from xml to annotation.

ManagedBean annotation worked fine when extends UserAction is removed. UserAction is a request scoped bean & UserConsoleAction is session scoped.

Valsaraj Viswanathan
  • 1,473
  • 5
  • 28
  • 51
  • Which annotations do you use? Please post packagenames – Kukeltje Oct 30 '18 at 13:09
  • import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; – Valsaraj Viswanathan Oct 31 '18 at 12:50
  • Does using the xml config still make it work? Only thing I can think of is that the default is to 'eager' create the beans then if xml is used. Tried if `@ManagedBean(name="user", eager="true")` solves it? But better to **NOT USE** these annotations since they are already deprecated. Better to switch to using CDI https://stackoverflow.com/questions/11986847/java-ee-6-javax-annotation-managedbean-vs-javax-inject-named-vs-javax-faces – Kukeltje Oct 31 '18 at 13:20
  • Yes, xml config working always. I checked eager already, but not luck. – Valsaraj Viswanathan Nov 01 '18 at 09:02

0 Answers0