Adding navigation rules to JSF components
Use navigation rules if you want to create navigation from one Faces JSP page to another in the same project. Navigation rules are the rules you set for which page to go to when a certain outcome occurs on the original page. For example, if a user receives an error message while trying to click a
Submit button, a navigation rule can automatically navigate to a new page that tells the user how to fix the problem.
Note: If you want to create navigation to external Web pages, use the Link component. Drag the Link component to the page and then specify the external target and label. To create navigation rules:
- Create and select one of the following components on the page:
Open the Properties view for the component.
- Button - Command
- Link - Command
- Link - Request
- The row action of a data table component
- Click the Quick Edit View button on the Properties view to switch to Quick Edit view and code an action that this component can perform. The action must return at least one value.
- In the Properties view, click
Add Rule. The Add Navigation Rule dialog opens and you can set the navigation rules for this component on this page.
- In the Add Navigation Rule dialog:
- In the
Go to the page section, select the page to which you want to navigate.
- In the
When the action returns the outcome section, choose "Any outcome" or name an outcome.
- In the
This rule is used for/by section, choose to have the navigation rule used by all pages or this page only and to have the rule used by any action or the action you specify.
- In the
When following this rule section, choose to have the parameters work automatically (request forwarding) or to have the parameters coded (request redirection). Note that you can set parameters on the
Parameter tab of the Properties view for this component.
- Click OK. The rule is added to the table in the Properties view.
At a minimum, you can select the component, then change return null to return "alias" in the Quick Edit view. By default, the alias will be *, which means a return code of anything (except null) will trigger that navigation rule. You can set the return code for a given component in the Quick Edit view. Select the Command event and in the right pane of the Quick Edit view, specify at a minimum: return"". This returns an empty string, which triggers the rule based on *. If you have a specific alias set up (for example, "success"), then the actions needs to return "success" to trigger that navigation rule. You can make a navigation rule apply only to a specific action (choose action in scope). You can have the navigation rule apply on the current page or on all pages in the project. Note that unless you scope it to a particular action, all actions use these navigation rules, whether or not you have explicitly added them using the Properties view.