The JavaServer Faces (JSF) Navigation Framework provides navigation rules that allow you to define navigation from view to view (mostly JSP pages) in a Web application. These navigation rules are defined in JSF configuration files along with other definitions for a JSF application. Usually , this file is named
Faces-config.xml. However, you can assign, Other Name and Even Use More Than One File to Store JSF Configuration Data. To Specify Configuration Files, Use Lines Like The Following In Your
Web.xml file:
Code:
A Simple Example The Actual Construction of a Navigation Rule Is Quite Simple. Let's Look AT Our First Example:
Code:
This code specifies that view /pages/inputname.jsp has two outputs, sayHello and sayGoodbye, associated with particular pages. Making a Default Outcome Case The basic construction is simple, but there are many variations you can do on the basic construction. Look at The next snippet:
Code:
Code:
THIS Navigation rule will be coplied for any page limited HAS / PAGES / AS The Asterisk Must Be Located At the Asterisk Must Be Located At the End. For Example, a Pattern Such AS / Pages / * .jsp Would Not Work. Resolving More Than Matching Rule Now Let's Pay More Attention To How Rules Can Be Specified in The JSF Navigation Model. Look At this next example:
Code:
Code:
THE FIRST SNIPPES An Asterisk for the from-view-id Element, While The Second Snippet Doesn't Use a from-view-id element at all. Both Approaches Work The Same. Note Though, That An Empty from-View-ID Element, AS Displayed In The Snippet Below, Will Not Work At AllCode:
Collision of Rules Here is an inTeresting Question. What happens when a couple of navigation rules That Have The Same from-view-id and the same from-outcome point to diffreent Pages. Look at the next esample:
Code:
The last rule is always used in such a situation. Also, remember, we spoke at the very beginning of this article about the possibility of splitting JSF configuration data into several files. In the case where the competing rules are in different configuration files, the rule in the last loading configuration file as listed in the web.xml file prevails Spreading Out Parts of a Navigation rule This is one more variation on the same theme Compare the following snippets:.. Code:
Code:
Both snippets produce the same result at run-time. However, the second snippet shows that the declaration can be arbitrarily split up and spread out into different parts of a configuration file or even different configuration files. You can use either approach based on your own . preferences Navigation Rules in Action Now, it is time to lift the veil a little to see how what we've learned can be put to use in an application A JSP page might contain the following line:. Code:
The Action Attribute Will Be Used as an outcome. Or, here is another variation:
Code:
This means that the helloAction method of GetNameBean will be invoked and the result will be used as an outcome. HelloAction should be a public method that returns String. This distinction between two ways of specifying the action attribute is significant in considering an element in the configuration File We Haven't Looked At Yet. This is the from-action element. Look at the Following Code:
Code:
In this code, both navigation cases have the same from-view-id and from-outcome, however the second navigation case includes a from-action element. If the sayHello outcome is determined by GetNameBean.helloAction, the second navigation case will take effect , but only because otherwise both cases had equal precedence Review Let's check how well you understand the material The page /pages/inputname.jsp has the following declaration for commandButton:.. Code:
The JSF Configuration File Contains The Following Code:
Code:
If The Submit Button Mentioned Above Is Pressed, What Will The next page /a.jsp or /b.jsp if getNameBean.HelloAction Returns Sayello?