Navigation to pages in subfolders in JSF 2 does not work

0

I have the following problem: I have a hierarchy of folders where I separate my web pages from the project:

Web
 |- Acoes
 |   |- usuariosAcoes.xhtml
 |   |- cadastrarAcao.xhtml
 |- usuarios
 |   |- listarUsuarios.xhtml
 |   |- cadastrarUsuario.xhtml

But when I try to navigate through ManagedBean the pages do not load, it only updates the current page if I try to access a page that is outside the current page's folder.

For example, if I am on the page listUsuarios.xhtml and I try to access the page registerUsuario.xhtml via ManagedBean everything works:

public String acessaCadastro(){ return "cadastrarUsuario"; }

But if I'm on the page list UUsuarios.xhtml and I try to access usersAx.xhtml that is in another folder, nothing happens, just reload the page I'm already in:

public String acessarAcoesUsuario(){ return "usuariosAcoes"; }

I tried this way but it did not work:

public String acessarAcoesUsuario(){ return "Acoes/usuariosAcoes"; }

Not so:

public String acessarAcoesUsuario(){ return "../Acoes/usuariosAcoes"; }

And not so:

public String acessarAcoesUsuario(){ return "Acoes/usuariosAcoes.xhtml"; }

or

public String acessarAcoesUsuario(){ return "../Acoes/usuariosAcoes.xhtml"; }

So, how can I resolve this issue? Remembering that I do not use faces-config.xml to create routes, since JSF 2.x already abstracts this.

    
asked by anonymous 09.11.2015 / 15:10

1 answer

1

I believe this helps you.

public void seuMétodo() {
    ExternalContext externalContext = FacesContext.getCurrentInstance()
                .getExternalContext();
    try {
          externalContext.redirect(externalContext.getRequestContextPath()
                + "/pastaDoArquivo/arquivo.xhtml");
    } catch (IOException e) {
          e.printStackTrace();
    }
}

Where would be called seuMétodo instead of your return "algumaCoisa.xhtml" .

Note : I usually isolate the navigation logic in a specific class, such as a "navigationManagedBean", which will store all my paging calls.

Any questions, leave in the comments.

Embrace

    
09.11.2015 / 16:02