How to redirect page in JSF?

1

I have a system with a form where you can edit or remove items. There is a link to redirect another page.

What form can I redirect a page to in JSF?

    
asked by anonymous 29.09.2017 / 17:20

1 answer

4

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. That 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

Redirect means making a new request. The redirect can point to out-of-context pages (www.uol.com, for example). Redirecting the address bar URL is changed and 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 extent of pagina . This is optional.

XHTML

In XHTML use the action attribute within the tag you want. Ex:

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