20
Mar

Navigation in JSF

   Posted by: Vivek Khokhar   in java

Navigation Rules are specified in faces-config.xml by default.
However, you can assign any 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:

<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml,/WEB-INF/faces-config2.xml</param-value>
</context-param>

Navigation rules are just like switch case constructs.

For example :

<navigation-rule>
<from-view-id>/pages/input.jsp</from-view-id>
<navigation-case>
<from-outcome>sayHello</from-outcome>
<to-view-id>/pages/greeting.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>sayGoodbye</from-outcome>
<to-view-id>/pages/goodbye.jsp</to-view-id>
</navigation-case>
<navigation-case>
<to-view-id>/pages/default.jsp</to-view-id>
</navigation-case>
</navigation-rule>

is similar in semantics to following Switch case

Switch(output from input.jsp){
case “sayHello”:
jump to /pages/greeting.jsp
break;
case “sayGoodbye”:
jump to /pages/goodbye.jsp
break;
default:
jump to /pages/default.jsp
break;

}

The <from-action></from-action> adds another level of checking while matching Navigation rules.
for example snippet below.. tells to jump to /pages/hello.jsp if hello was returned from GetSomeBean.someAction
<navigation-case>
<from-action>#{GetSomeBean.someAction}</from-action>
<from-outcome>hello</from-outcome>
<to-view-id>/pages/hello.jsp</to-view-id>
</navigation-case>
Here’s an excellent tutorial for this: http://www.jsftutorials.net/jsf-navigation-by-examples.html

This entry was posted on Monday, March 20th, 2006 at 8:48 am and is filed under java. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a reply

You must be logged in to post a comment.