Re-direct

Normally, when a Redirect is encountered by the Server, then the current request is terminated, the control is directed back to the browser and the Browser makes the request (which will be available as a URL in the Redirect instruction). The same happens here also. For example, consider the following code snippet,


<navigation-case>
    <from-outcome>loginFailure</from-outcome>
    <to-view-id>/loginFailure.jsp</to-view-id>
    <redirect/>
</navigation-case>

Specifying wild-cards

It is also possible to specify wild-card character (*) in the 'from-view-id' element. For example, say that we want to handle the navigation mechanism for all jsf files within the folder 'registration', then we can have something like the following,


<navigation-rule>
    <from-view-id>/registration/*</from-view-id>
    <navigation-case>
        ...
    </navigation-case>
</navigation-rule>

Other

The from-outcome element for the second navigation-case is missing. This means that all outcomes except sayHello, will be forwarded to /pages/goodbye.jsp

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

"Global" Outcomes

<navigation-rule> 
    <from-view-id>*</from-view-id> 
    <navigation-case> 
      <from-outcome>globalhelp</from-outcome> 
      <to-view-id>/menu/generalHelp.jsp</to-view-id> 
    </navigation-case> 
</navigation-rule> 
or
<navigation-rule> 
    <navigation-case> 
      <from-outcome>globalhelp</from-outcome> 
      <to-view-id>/menu/generalHelp.jsp</to-view-id> 
    </navigation-case> 
  </navigation-rule> 

Navigation Rules in Action

<h:commandButton id="submit" action="sayHello" value="Submit" /> 
The action attribute will be used as an outcome.

Or, here is another variation:

<h:commandButton id="submit" action="#{GetNameBean.helloAction}" value="Submit" /> 
 

The JSF configuration file contains the following code:

<navigation-rule> 
   <from-view-id>/pages/inputname.jsp</from-view-id> 
    <navigation-case> 
      <from-outcome>sayHello</from-outcome> 
      <to-view-id>/a.jsp</to-view-id> 
    </navigation-case> 
  </navigation-rule> 

<navigation-rule> 
   <from-view-id>/pages/*</from-view-id> 
    <navigation-case> 
      <from-action>#{GetNameBean.helloAction}</from-action> 
      <from-outcome>sayHello</from-outcome> 
      <to-view-id>/b.jsp</to-view-id> 
    </navigation-case> 
  </navigation-rule>