Problem with redirect JSF+Primefaces

Asked

Viewed 473 times

2

I have a menu where I have a submenu Register and inside it a menuItem Usuários in my template, and also have a menuItem Sair. The problem is that the exit only works on the screen Home, 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";
    }

1 answer

5


Change your method sair() for :

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

Follows the link of Soen, where there are other alternatives.

  • It didn’t work, and also if I put this in my method it returns an error string.

  • In your <p:menuitem> put ajax = "false".

  • all right, I’ll try

  • It hasn’t worked yet, the usuarioLogado receives null but the page is not redirected

  • Exit only works normally on the Home page

  • Anyway, I used one of the options that are in the link Voce sent me and it worked. Thanks

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.