0

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.

  • 1
    Does it throw an exception ? does it return "exito" ? what do you mean by it doesn't work ? – Jean-François Savard Apr 02 '15 at 11:52
  • No exception is thrown and it returns "exito". By it doesn't work I mean that in the page that I try to access, the login, name, surname and all that data is not filled in the text fields, like if the object I'm trying to call is null. Or when I try to go to a page where the data is in tables (like the emails from a given username), there isn't any data there. I've just debugged the code and returns the "Usuario", but with all the values empty, null or 0. – dot.pointer Apr 02 '15 at 11:57
  • 1
    If `Usuario` is a true session scoped managed bean, `usuario.setUsuario(usermodificar);` correctly sets a value to that session scoped managed bean and `Usuario usermodificar = (Usuario) getObjectFromSession("LOGGEDIN_USER");` correctly retrieves the value stored into that session scoped managed bean, then this should function normally. You may want to debug/trace these statements, if it does not work as you expect - the above-mentioned method may not retrieve the value - it is likely that it is not stored into the session scoped bean or stored with a different key than `LOGGEDIN_USER`. – Tiny Apr 02 '15 at 19:29

0 Answers0