Starting with Java EE and JSF, I need to create a simple login and keep the id and nick of the user in the session.
For that, create a class
package Controlador;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean
@SessionScoped
public class SessionBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1;
private int usuarioId;
private String usuarioNick;
public SessionBean() {
super();
}...
From another class I try to save data in it, but when I try to access it returns Null pointer exception
.
@ManagedBean
b@SessionScoped
public class UsuarioSessionBean {
@EJB
private UsuarioSessionDAO usuarioSession;
@ManagedProperty("#{sessionBean}")
private SessionBean sessionBean;
public void setSessionBean(SessionBean sb){
if(sb != null){
this.sessionBean = sb;
}
}
...
public String Login(){
Usuario usr = usuarioSession.Login(usuario.getNick(), usuario.getPass());
if(usr != null){
sessionBean.setUsuarioId(usr.getId());
sessionBean.setUsuarioNick(usr.getNick());
return "loginOk";
}
return "loginNo";
}
What am I doing wrong? Or rather, what would be the way to create a simple login?