How to redirect page in JSF?

Asked

Viewed 2,246 times

1

I have a system with a form in which you can edit or remove items. In it there is a link to redirect another page.

telaFormulario

What form it is possible to redirect a JSF page?

  • See help: https://stackoverflow.com/questions/4032825/how-to-make-a-redirection-in-jsf

1 answer

5


Redirect is a specific term.
You can redirect or forward:


Forward

Forwarding means taking the user to another page within the same context without a new request being made.
This way, the URL in the browser’s address bar does not change. Continue with the address of the old page.
Ex:

@ManagedBean
public class TesteMB {

    public String encaminha() {
        return "pagina";
    }
}

Redirect

Redirecting means making a new request. Redirecting can point to out-of-context pages (www.uol.com.br, for example).
When redirecting the address bar URL is changed, it is updated to the address of the page in question.
Ex:

@ManagedBean
public class TesteMB {

    public String redireciona() {
        return "pagina?faces-redirect=true";
    }
}

Note that in neither case was it necessary to include the extension of pagina.
This is optional.


XHTML

In XHTML use the attribute action inside the desired tag.
Ex:

<p:commandButton action="#{testeMB.encaminha}" />
<p:commandButton action="#{testeMB.redirectiona}" />

Browser other questions tagged

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