How to get JSF 2.0 to update the address bar

On January 7, 2011, in JSF, JSF 2.0, by lucasterdev

By default, JSF 2 is perform a forward while navigating to another page, it caused the page URL is always one behind :) . For example, when you move from “page1.xhtml” to “page2.xhtml”, the browser URL address bar will still showing the same “page1.xhtml” URL.

To solve this, do one of the folowing:

Append the “?faces-redirect=true” to the end of the “outcome” string returnet by the method invoked by the “action” attribute,

OR

Append the “faces-redirect=true” to the end of the the “action” attribute.

<h:form>
<h:commandButton action="page2?faces-redirect=true" value="Move to page2.xhtml" />
</h:form>

OR (best way)

In the navigation rule, you can enable the page redirection by adding a <redirect /> element within the <navigation-case />.

<navigation-rule>
	<from-view-id>start.xhtml</from-view-id>
		<navigation-case>
			<from-outcome>page2</from-outcome>
			<to-view-id>page2.xhtml</to-view-id>
			<redirect />
		</navigation-case>
</navigation-rule>
 

Leave a Reply