PhaseListener + erro loop infinito

1 resposta
rodrigoalves639

Estou com um problema no meu phaseListener, ele executa o metodo afterPhase verifica todas as condicoes, mas nunca para de executar o metodo afterPhase.

import javax.faces.application.NavigationHandler;

import javax.faces.context.FacesContext;

import javax.faces.event.PhaseEvent;

import javax.faces.event.PhaseId;

import javax.faces.event.PhaseListener;

import javax.servlet.http.HttpSession;

public class AuthorizationListener implements PhaseListener {

public void afterPhase(PhaseEvent event) {

    FacesContext facesContext = event.getFacesContext();
    String currentPage = facesContext.getViewRoot().getViewId();

    boolean isLoginPage = (currentPage.lastIndexOf("login.jsf") > -1);
    HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(true);
    Object currentUser = session.getAttribute("currentUser");

    if (!isLoginPage && currentUser == null) {
        NavigationHandler nh = facesContext.getApplication().getNavigationHandler();
        nh.handleNavigation(facesContext, null, "loginPage");
    }
}

public void beforePhase(PhaseEvent event) {
}

public PhaseId getPhaseId() {
    return PhaseId.RESTORE_VIEW;
}

}

Eu nao sei se minha classe AuthorizationListener esta com erro ou se eu estou implementando de forma errada no meu faces config:

br.com.inloc.sessao.AuthorizationListener /*3 loginPage forwardToJSF.jsp

Se alguem puder ajudar fico grato, valeu d+

1 Resposta

R

Também tive esse problema e consegui resolver da seguinte forma:

No meu faces-config.xml, eu estava mapeando o JSF como *.xhtml

Faces Servlet javax.faces.webapp.FacesServlet 1 Faces Servlet [b] *.xhtml[/b]

Tive que alterar o código do phaseListener.

Substituí a linha:

boolean isLoginPage = (currentPage.lastIndexOf(“login.jsf”) > -1);

Por:

boolean isLoginPage = (currentPage.lastIndexOf(“login.xhtml”) > -1);

E funcionou legal.

Criado 7 de janeiro de 2010
Ultima resposta 25 de ago. de 2012
Respostas 1
Participantes 2