I am trying to access an ID used to log into my interface in another class for an SQL query.
I am currently using:
public void login (String UName)
{
try
//sql stuff
FacesContext context = FacesContext.getCurrentInstance();
Map<String, Object> userdata = context.getExternalContext().getSessionMap();
UserBean userBean = new UserBean();
userBean.setUserID(rs.getString(1).toString());
userBean.setMajor(rs.getString(5).toString());
userdata.put("userBean", userBean);
}
Which allows me to get the userID, and I can display that data on JSF webpage.
However, I want to get that ID in another java class, ie viewregistereduserID.java. So, for example, I want to get the UserID used to login as a string that can be used for other methods.
I have tried using UserBean userBean = (UserBean) userdata.get("userBean"); and @ManagedProperty(value="#{userBean}") but the result comes out as null both times when I tried userBean.getUserID.
I used @SessionScoped for both java classes in this example.
Does anyone know how I can acess the data in a string?