JSF: Lesson – 3: Controlling Page Navigation in JSF #Java Short Notes

  • Sample application for this article
  • Video Tutorial for this article
  • Pre-requisite: JSF Lesson 1 & 2
  • Navigation: Two Types:
    • Static: The destination page is fixed
    • Dynamic: The destination page varies with the conditions
    • Static
      • Static: You provide a fixed value for the "action" attribute for a JSF event control/action element
      • That fixed value is mapped to the fixed destination page in the configuration file such as the faces-config.xml
      • If you check our previous lesson, the searchForms.jsp contains . In this line, the text 'action="submit"' defines the static navigation.
      • The navigation rule in the following text maps submit action to searchResults.jsp page [static/fixed mappping]
        /searchForm.jsp

        submit
        /searchResults.jsp

    • Dynamic Navigation
      • In this case, the action takes a dynamic value. All possible values are mapped into [different] destination pages. Hence, when the action gets a different value, the destination page is also different [unless mapped to the same destination page]
      • To get dynamic nature, the action is mapped to a value/property or a method of a managed bean. The property must be of String type. Also, the method must return String and must not take any parameter.
      • At the time, the action is executed [the button is pressed], corresponding property value is retrieved or the method is called to get value. This value is then matched with the navigation cases in faces-config.xml.
      • The user is then redirected to the destination of the mathching navigation case.
      • Example: Binding action to a value/method expression in jsp: . Here, search is a method in the bus bean. Hence, at the button click, the search method is executed. For example, it may get values such as success, noTrips
      • Mapping in faces-config.xml: success, and noTrips are mapped in the following navigation cases.
      • /searchForm.jsp

        success
        /searchResults.jsp

        noTrips
        /noTrips.jsp

  • Navigation Rules:
    • If you observe the navigation rules above, you will notice elements. This is to mention, from where the action is generated.
    • : is the action message based on which flow is maintained
    • element provides the destination page
    • is optional. If you omit , then for all <from -outcome&gt message for the application, will be redirected to the related destination page. If all page refers to the same privacy policy file, this rule can be useful
    • Example:

      privacy-policy
      /WEB-INF/privacy.jsp

    • You can also redirect for the same message for a group of pages to the same destiation. Such as:
      /order/*
      success
      /WEB-INF/invoice.jsp
    • element: Consider a case, in the same page, in two command buttons, the actions are mapped to save and search methods. Both save and search methods can return success as the element. But, if you want them (two successes from the two methods) to go to two different destination pages, then element comes handy.
    • You can use element in the following way:
    • /searchForm.jsp

      #{bus.search}
      success
      /searchResults.jsp

      #{bus.save}
      success
      /searchForm.jsp

  • Now check the sample example and the video.
  • From: http://sitestree.com/?p=4994
    Categories:Java Short Notes
    Tags:
    Post Data:2012-08-07 12:03:08

    Shop Online: https://www.ShopForSoul.com/
    (Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
    In Bengali: http://Bangla.SaLearningSchool.com
    http://SitesTree.com
    8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
    Shop Online: https://www.ShopForSoul.com/
    Medium: https://medium.com/@SayedAhmedCanada

    Leave a Reply