HTML and CSS Reference
In-Depth Information
Rule-Based Navigation
In rule-based navigation, the navigation rules are defined in the Faces configuration file ( faces-config.xml ).
Rule-based navigation consists of a set of navigation rules. Every navigation rule can have one or more navigation case(s).
Listing 2-28 shows a rule-based navigation example.
Listing 2-28. Rule-Based Navigation Example 1
<faces-config ...>
<navigation-rule>
<from-view-id>/index.xhtml</from-view-id>
<navigation-case>
<from-action>#{exampleBean.doAction}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>/welcome.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-action>#{exampleBean.doAction}</from-action>
<from-outcome>fail</from-outcome>
<to-view-id>/invalid.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
As shown in the example, the navigation rule can contain the following elements:
<from-view-id> (Optional), which represents the view from which the navigation starts.
<navigation-case> , which can be from 1 to N inside the navigation rule.
The navigation case can contain the following elements:
<from-action> (Optional), which holds an EL expression which refers to an action method
that returns a String (outcome).
<from-outcome> , which represents a String literal outcome. In the presence of the <from-
action> element, the <from-outcome> value is compared with the <from-action> returned
outcome, and if the two values are matched then the navigation proceeds to the <to-view-
id> . If the <from-action> element is not present then the <from-outcome> is compared with
the action attribute of the action source components, and if the two values are matched
then the navigation proceeds to the <to-view-id> (will be illustrated in the next navigation
example).
<to-view-id> , which represents the target view.
Looking back in the example, starting from the index.xhtml page, the first navigation case fires when the
#{exampleBean.doAction} action method is executed and returned the "success" outcome; in this case, the page will
be forwarded to the welcome.xhtml page. The other navigation case fires when the #{exampleBean.doAction} action
method is executed and returns the "fail" outcome; in this case, the page will be forwarded to the invalid.xhtml
page. Listing 2-29 shows the important part of the ExampleBean managed bean.
 
Search WWH ::




Custom Search