Problem with redirect JSF + Primefaces

2

I have a menu where I have a Registry submenu and inside it a menuItem Usuários in my Template, and I also have a menuItem Sair . The problem is that logging out only works on the Home screen, which is the screen that is called after login. When I enter the registration screen and having exit the system is not redirected to main page.

<h:form style="display: inline-block" id="frmPrincipal">
            <p:menubar styleClass="menu-sistema" id="menuBar">

                <p:submenu label="Cadastros" rendered="#{usuarioBean.usuarioLogado.cargo == 'Administrador'}">
                    <p:menuitem value="Usuários" outcome="/usuario/cadastroUsuario" />
                </p:submenu>
                <p:menuitem value="Sair" action="{usuarioBean.sair}" update=":frmPrincipal:menuBar"/>
            </p:menubar>

The exit method is as follows:

public String sair() {
        usuarioLogado = null;
        return "Login.xhtml?faces-redirect=true";
    }
    
asked by anonymous 13.07.2015 / 21:19

1 answer

5

Change your method sair() to:

public void sair() {
        usuarioLogado = null;
        ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
        ec.redirect(ec.getRequestContextPath() + "/Login.xhtml");
}

Follow the link of SOen, where you have other alternatives.

    
13.07.2015 / 21:31