Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Session Scoped Bean data in another ManagedBean

Tags:

jsf-2

I am trying to get session scoped bean data in another Managed bean. When I am doing that value is coming as null and giving java.lang.NullPointerException error. I am new to JSF so keep in mind that I might be missing simple thing.

Here is the SessionScoped Bean

    @ManagedBean
    @SessionScoped

    public class UserSessionBean {
      private superProcessId;

      //getter setter and other code
    }

Here is the Managed Bean I am trying to get this data

@ManagedBean
public class AddProcessBean {
  @ManagedProperty(value="#{UserSessionBean}")
  private UserSessionBean sessionData;

  //Getter Setter for sessionData
  public UserSessionBean getSessionData() {
    return sessionData;
  }

  public void setSessionData(UserSessionBean sessionData) {
    this.sessionData = sessionData;
  }

  public void addAction() {
    System.out.println(getSessionData().getSuperProcessId());
  }
}
like image 718
SXV Avatar asked Mar 07 '13 11:03

SXV


1 Answers

Your value is not good in @ManagedProperty. Use:

@ManagedProperty(value="#{userSessionBean}")

Default name for bean is same as class name with lower first letter. Also scope of your bean whose managed property is should be session or lower (view, request).

like image 82
partlov Avatar answered Nov 15 '22 01:11

partlov