By default, JSF is perform a server page forward while navigating to another page. See following example to differentiate between the page forward and page redirect.

Example

A “start.xhtml” page, with a button navigate to “page1.xhtml” page.

1. Page Forward

Here’s how the page forward works :

  1. Browser send a “GET” request to URL : http://localhost:8080/JavaServerFaces/faces/start.xhtml.
  2. JSF received the request and return the “start.xhtml“.
  3. Browser display the content of “start.xhtml“.
  4. User click on the button.
  5. JSF received the action and perform an internal page forward to “page1.xhtml” in the server side.
  6. JSF return the “page1.xhtml“.
  7. Browser display the content of the “page1.xhtml“.

In the page forward, the browser’s URL is not update.

jsf2-page-forward-example

2. Page Redirection

Here’s how the page redirection works :

  1. Browser send a “GET” request to URL : http://localhost:8080/JavaServerFaces/faces/start.xhtml.
  2. JSF received the request and return the “start.xhtml“.
  3. Browser display the content of “start.xhtml“.
  4. User click on the button.
  5. JSF received the action and send back a “redirect” to “page1.xhtml” response back to the browser.
  6. Browser received the response and send another “GET” request to URL : http://localhost:8080/JavaServerFaces/faces/page1.xhtml.
  7. JSF received the request and return the “page1.xhtml“.
  8. Browser display the content of the “page1.xhtml“, and the browser’s URL is updated.
jsf2-page-redirection-example

To enable the page redirection in JSF 2.0, you can append the “faces-redirect=true” to the end of the outcome string.

Page forward.

     action="page1" value="Page1" /> </h:form>

Page redirection.

     action="page1?faces-redirect=true" value="Page1" /> </h:form>

In the navigation rule, you can enable the page redirection by adding a element within the .

 	start.xhtml 	 		page1 		page1.xhtml 		 /> 	 

Conclusion

The default page forward mechanism is more faster if compare to page redirection, because the page redirect added extra HTTP request to the server. So, only enable the page redirect when necessary, for example use thePost/Redirect/Get Design Pattern to solve the classic duplicated form submission problem.

Download Source Code