I'm currently trying to retrieve all the data from the user that is logged in so I can use it for example listing his emails or his contacts, or to can modify or add new ones.
At the beginning, in the login screen, I use a method to put that user in session.
private void putUserInSession(Usuario user) {
Map<String, Object> session = FacesContext.getCurrentInstance()
.getExternalContext().getSessionMap();
session.put("LOGGEDIN_USER", user);
}
And to retrieve that user to show in a page his personal data in order to modify and update it, I use the following one in a call inside a .xhtml page, so as it returns "exito" (success) it will take me to the edit page.
public String proceed(){
Usuario usermodificar = (Usuario) getObjectFromSession("LOGGEDIN_USER");
usuario.setUsuario(usermodificar);
return "exito";
}
private Object getObjectFromSession(String key) {
return FacesContext.getCurrentInstance().getExternalContext()
.getSessionMap().get(key);
}
I try to set the bean values to the user in session, but no data is shown.
I also try to retrieve it inside other beans, like to save a given email inside the users account (so I need his or her ID)
Usuario usuario = (Usuario) getObjectFromSession("LOGGEDIN_USER");
But it doesn't work like the previous case.