Filtr logowania JSF, sesja ma wartość NULL

Próbowałem podążaćto odpowiedz przede wszystkim, ale zawsze otrzymuję przekierowanie na mój login.xhtml (z wyjątkiem sytuacji, gdy loguję się ze strony logowania), ponieważ ...

AppManager am = (AppManager) req.getSession().getAttribute("appManager");

Zawsze jest null. Próbowałem wydrukować informacje o użytkowniku na ekranie logowania i bez względu na to, jak tam dotrę, wszystkie pola (nazwa użytkownika, hasło, loggedIn ...) są zawsze zerowe, nawet jeśli wpisuję adres bezpośrednio ze strony administratora (to jest gdzie dostaniesz się po zalogowaniu). Jak zrobić, aby sesja została zapisana, a nie bita za każdym razem, gdy wpisuję adres ręcznie / opuszczam stronę?

Manager aplikacji:

import java.io.Serializable;
import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import jobapp.controller.Controller;

@ManagedBean(name="appManager")
@SessionScoped
public class AppManager implements Serializable {
private static final long serialVersionUID = 16247164405L;
    @EJB
    private Controller controller;
    private String username;
    private String password;
    private boolean loggedIn;
    private Exception failure;
    ...
     /**
     * 
     * @param e an exception to handle.
     */
    private void handleException(Exception e) {
        e.printStackTrace(System.err);
        failure = e;
        FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
    }

    /**
     * The login method.
     * calls the controllers login method.
     * 
     */ 
    public void login(){
        try{
            failure = null; 
            loggedIn = controller.login(username, password);

        }catch (Exception e){
            handleException(e);
        }
    }
    /**
     * The logout method.
     * Sets the user's info to null
     * and stops the conversation.
     */
    public void logout(){
        username = null;
        password = null;
        loggedIn = false;
        FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
    }
...

Filtr:

@WebFilter("/faces/admin.xhtml")
public class LoginFilter implements Filter {
...
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {    
        HttpServletRequest req = (HttpServletRequest) request;
        //TODO fix "am" nullpointer
        AppManager am = (AppManager) req.getSession().getAttribute("appManager");
        if (am != null && am.isLoggedIn()) {
            // User is logged in, so just continue request.
            chain.doFilter(request, response);
        } else {
            // User is not logged in, so redirect to login.
            HttpServletResponse res = (HttpServletResponse) response;
            res.sendRedirect(req.getContextPath() + "/faces/login.xhtml");
        }
    }

questionAnswers(1)

yourAnswerToTheQuestion