Navigation to pages in subfolders in JSF 2 does not work

Asked

Viewed 688 times

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, only update the current page if I try to access a page that is outside the folder of the current page.

For example, if I’m on the page listUsuarios.xhtml and I try to access the registration pageUsuario.xhtml via Managedbean everything works:

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

but if I am on the page listUsuarios.xhtml and I try to access usersAcoes.xhtml that is in another folder, nothing happens, just reload the page I am already on:

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

I tried so fearwell but did not solve:

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

even so:

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

and yet:

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

or

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

So, how can I resolve this issue? Remember that I don’t use faces-config.xml to create routes, since JSF 2.x already abstracts this.

1 answer

1


I think it 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 the seuMétodo in place of his return "algumaCoisa.xhtml".

Note: I usually isolate browsing logic in a specific class, like a "navigationManagedBean", which will store all my paging calls.

Any questions, leave in the comments.

Hug

  • Thanks @Weslley I will test and give you an answer

  • This way for me worked very well, thank you!!! The only thing is that I lost the URL capsulation, because before I did not appear all the way in the address bar, and now always appears for each page. But that’s just aesthetics

Browser other questions tagged

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