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());
}
}
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With