SXV
SXV

Reputation: 277

Get Session Scoped Bean data in another ManagedBean

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());
  }
}

Upvotes: 8

Views: 6840

Answers (1)

partlov
partlov

Reputation: 14277

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).

Upvotes: 11

Related Questions