Main Tutorials

How to add a global navigation rule in JSF?

Problem

A global navigation rule is a rule that applies to all pages. For example, apply a “logout” navigation rule that every pages are allow to access. Is there a way to configure it in JSF?

Solution

In JSF, wildcard is supported in navigation rule, you can use a “*” to specify a navigation rule that applies to all pages.


<navigation-rule>
   <from-view-id>*</from-view-id>
   <navigation-case>
	<from-outcome>logout</from-outcome>
	<to-view-id>logout.xhtml</to-view-id>
   </navigation-case>
</navigation-rule>

In this example, all the pages in your web application is able to access the “logout” navigation.

See another example,


<navigation-rule>
   <from-view-id>/customer/*</from-view-id>
   <navigation-case>
	<from-outcome>validation</from-outcome>
	<to-view-id>customer-validation.xhtml</to-view-id>
   </navigation-case>
</navigation-rule>

This rule applies to all pages that start with the prefix /customer/.

Note
The “*” wildcard functionality is limited in JSF, because only one “*” is allowed, and it must be at the end of the “form-view-id” string. For example,

It works.


<from-view-id>/customer/*</from-view-id>

It will never match…


<from-view-id>/cus*mer/</from-view-id>
<from-view-id>/c*sto*er/*</from-view-id>
<from-view-id>*/customer</from-view-id>

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
g raviteja
8 years ago

The “*” wildcard functionality is limited in JSF, because only one “*” is allowed, and it must be at the end of the “form-view-id” string.

Its from-view-id.
I’m new to JSF and I got confused whether its form and from.
BTW the article is clear and crisp and easily understandable.
Thank you.