tell me more icon Outcomes for Navigation Cases

A JSF configuration file can contain a number of navigation rules, and a number of navigation cases for each rule. In the example so far, the following navigation rule and navigation cases were automatically created for you in faces-config.xml when you created the JSF navigation diagram and added navigation cases in a previous cue card:

                               
<navigation-rule>
  <from-view-id>/Login.jsp</from-view-id>
  <navigation-case>
    <from-outcome>success</from-outcome>
    <to-view-id>/Success.jsp</to-view-id>
  </navigation-case>
  <navigation-case>
    <from-outcome>failure</from-outcome>
    <to-view-id>/Failure.jsp</to-view-id>
  </navigation-case>
</navigation-rule>
                            

In the navigation rule, the rule specifies how to navigate from the Login.jsp page to the other two pages, Success.jsp and Failure.jsp. In other words, the navigation rule has two navigation cases or two possible outcomes.

To specify which navigation case is to be used when a user clicks the command button on the Login.jsp page, you can specify an action method, an outcome, or both, for each case.

  • An outcome specifies that this navigation case is to be followed only if the specified string is returned. This form of navigation is static navigation: Whenever a user clicks the button or link, a defined, fixed JSF page is always displayed. The button or link itself uses the action attribute to specify the string outcome. For example, <commandButton value="Click" action="success"/>.

  • An action method specifies that this navigation case is to be followed only if the action method has handled the link. The action method performs some logic to determine the outcome and returns the outcome. The button or link itself uses the action attribute to specify the method expression that refers to the action method that returns the logical outcome. For example, <commandButton value="Click" action="#{somebean.somemethod}"/>.

  • Using both an action method and an outcome specifies that this navigation case is to be followed only if the specified action method handles the link, and only if it returns the specified string outcome.

Writing and Referencing Action Methods

In the example, you will use an outcome from an action method to determine which page to display next when the user clicks the Login button on the Login.jsp page. If the outcome is success, the Success.jsp page will be displayed; if the outcome is failure, the Failure.jsp page will be displayed.

To call the action method on the command button when the button is clicked, an method expression on the button's action attribute is used to refer to the method in the managed bean.

When you double-clicked the command button to use the Bind Action Property dialog, JDeveloper automatically did the following for you:

  • Created the starter action method in the LoginInfo.java source file:
                                       
    public Object commandButton1_action() {
        // Add event code here...
        return null;
    }
                                    
  • Bound the action attribute on the command button to the action method using a method expression:
                                       
    <h:commandButton value="Login" binding="#{backing_login.commandButton1}"
                     id="commandButton1"
                     action="#{backing_login.commandButton1_action}"/>
                                    

An action method must be a public method that does not accept parameters and returns an Object, which represents the logical outcome that the JSF NavigationHandler then compares to outcomes in navigation cases in the faces-config.xml file to determine which page to display next. So the event code that you will add to the generated action method should return both "success" and "failure", to cover the two possible navigation case outcomes from the Login.jsp page.

Copyright © 1997, 2009, Oracle. All rights reserved.

false ,,,,,,,,,,,,,,,