Retrieve data associated with a Bean session in another ManagedBean

I am trying to get scope bean data with sessions in another managed bean. When I make this value, it comes as null and gives a java.lang.NullPointerException error. I am new to JSF, so keep in mind that I can skip the simple thing.

Here is a SessionScoped Bean

@ManagedBean @SessionScoped public class UserSessionBean { private superProcessId; //getter setter and other code } 

Here is a managed bean I'm 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()); } } 
+7
source share
1 answer

Your value is not suitable for @ManagedProperty . Using:

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

The default name for the bean matches the class name with the lower first letter. Also, the area of ​​your bean, the managed property of which should be a session or lower (view, request).

+11
source

All Articles