im trying to keep a SessionBean scoped throug my pages, and for this, i followed some tutorials from here, and actually, I'm trying to get the session throug ExternalContext, like the following code:
public class LoginFilter implements Filter{
ProfileBean pBean = new ProfileBean();
ActiveUserModel activeUserModel;
ExternalContext tmpEC;
Map sMap;
public void destroy() {}
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
tmpEC = FacesContext.getCurrentInstance().getExternalContext();
sMap = tmpEC.getSessionMap();
activeUserModel = (ActiveUserModel) sMap.get("ActiveUserModel");
String username = SecurityAssociation.getPrincipal().getName();
if(activeUserModel.getUsername() == null)
{
try {
pBean.consultaProfile(username);
} catch (SQLException e) {
e.printStackTrace();
} catch (NamingException e) {
e.printStackTrace();
}
}else{
}
filterChain.doFilter(servletRequest, servletResponse);
}
public void init(FilterConfig filterConfig) throws ServletException {}
}
In this line if(activeUserModel.getUsername() == null), i get a java.lang.NullPointerException because I'm not instantiating the bean, but even if I instantiate it, didn't work.
There is something wrong?