JSF Dynamic Navigation and how to use wildcard in navigation

 

101317_0313_Wildcarddyn1 JSF Dynamic Navigation and how to use wildcard in navigation

 

In this section, I have explained an example of JSF dynamic navigation and how to use a wildcard character in the URL Navigation.

 

I have created a JSF page called index.Xhtml has two set of links, home & dashboard. The URL navigation occurs dynamically based on the link clicked.The browser loads the home.Xhtml by clicking on the link ‘home’ and the dashboard.xhtml will load on clicking the link ‘dashboard’.

One set of link hit faces-config.xml through managed bean, and another set of link hit directly faces-config.xml for navigation rule, So we can control the navigation in Java class. Also, I have used wildcard character * in the <from-view-id/>. The wildcard rule * applies for all the pages, that is we can place these two links in all the JSF pages, and the navigation occurs as expected.

Let’s go through the example:

 

Below is the index.xhtml. This page has two set of links as shown below. The first set has direct action message and the second set calls managed bean methods. 

 

 

Below is the content of the home.Xhtml page. A simple message displaying this is a Home page 

 

 

Below is the content of the dashboard.Xhtml file. A simple message displaying this is a Dashboard page 

 

 

Below is the Managed Bean class with the getText() method. It either returns ‘home‘ or ‘dashboard‘. 

 

 

Below is the navigation rule mentioned in faces-config.xml file . I put * in the <from-view-id>; That is the <navigation-rule> works for all the pages.  Below are some examples of wildcard patterms: 

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

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

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

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

<from-view-id>/servicerequest/SR-*</from-view-id>

 

 

 

This is how it works in the browser

 

JSF_Wildcard_Dynamic_Navigation_Example JSF Dynamic Navigation and how to use wildcard in navigation

 

Download the Project: JSF_Dynamic_Navigation

govindan JSF Dynamic Navigation and how to use wildcard in navigation
Connect me

Govind

Thank you for visiting my personal blog. Myself Govindan, Software Developer by profession since 2006 and hence I started this blog early in 2016 and ever since I've been writing about technologies experienced and learnings of everyday life.

The views expressed on this blog are my personal views and do not necessarily reflect the views of my employer.

Please feeling free to reach me on any comments and feedbacks you have. Would be more than glad to listen and reply šŸ™‚
govindan JSF Dynamic Navigation and how to use wildcard in navigation
Connect me
By | 2017-10-12T23:43:23+00:00 October 12th, 2017|Categories: JSF|Tags: , , |0 Comments
Like us on Facebook.
Connect!