[RESOLVIDO] Problema Session Managed Bean

4 respostas
Lennon_Manchester

Estou com um problema com logout utlizando um Managed Bean com Session Scope, quando dou logout a sessão é expirada, mas os valores que são setados no managed bean quando o usuario se loga, não são perdido.

Preciso de um jeito de resetar o Managed Session bean.

Ja tentei fazer um metodio de logout com esse comando:
FacesContext.getCurrentInstance().getApplication().createValueBinding("#{autenticador.pais}").setValue(FacesContext.getCurrentInstance(),null);
Ja tentei com esse
HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
        if (session != null) {
            session.invalidate();
        }
Ja tentei colocar um PhaseListener para setar os caches das paginas como nulo.
public void beforePhase(PhaseEvent event) {
		public class CacheControlPhaseListener implements PhaseListener {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

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

	public void afterPhase(PhaseEvent event) {

	}

	public void beforePhase(PhaseEvent event) {
		
		FacesContext facesContext = event.getFacesContext();
		
		HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
		response.addHeader("Pragma", "no-cache");
		response.addHeader("Cache-Control", "no-cache");
		response.addHeader("Cache-Control", "must-revalidate");

		response.addHeader("Expires", "Mon, 8 Aug 2006 10:00:00 GMT");
	}

}

Alguem sabe como posso resolver isso?

vlw

Att,
Lennon

4 Respostas

E

Ja tentou o Session.clear() ?

Lennon_Manchester

Session.clear()??

Da onde vc tirou isso?

Ahh… para ajudar vou colocar o metodo de deslogar do meu managed bean :

public String deslogar() {
		
		FacesContext fc = FacesContext.getCurrentInstance();
		
		ELContext elContext = fc.getELContext();
		FacesContext.getCurrentInstance().getApplication().getELResolver().setValue(elContext, null, "autenticador", null);
 
		if (fc.getExternalContext().getSessionMap().containsKey("autenticador")) {  
			fc.getExternalContext().getSessionMap().remove("autenticador");  
		}  
		
		HttpSession session = (HttpSession) fc.getExternalContext().getSession(false);
		
	       session.setAttribute("autenticador", null);
		
		if (session != null) {
			session.invalidate();
		}
		return "logout";
	}

e o mapeamento dele no facesconfig:

<managed-bean> <managed-bean-name>autenticador</managed-bean-name> <managed-bean-class>br.com.projeto.handler.LoginHandler</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean>

vlww

Lennon_Manchester

Puuuuuuuuuuuuuuuuuutz… resolvido, estava com um problema na verdade em outro lugar, eu pegava um atributo da sessão e adiciona em uma SessionFilter. :?

vlw

abs

E

Vixe … viajei mesmo.

Criado 20 de julho de 2009
Ultima resposta 21 de jul. de 2009
Respostas 4
Participantes 2