j2ee_-_jsf_-_mastering_java_server_faces_-_wiley_-_2004

Page 251

224

Chapter 7

scenario. We’ll learn how to code action methods that provide the required application logic, as well as how to configure navigation rules in the application configuration file (by default, faces-config.xml) to manage the application’s page flows. We’ll also learn about how and when to implement ActionListeners and ValueChangeListeners to handle some of the subtler issues that can arise when using JSF to develop nontrivial Web applications.

Actions and Navigation Implementations of JSF must provide an implementation of the Action Listener interface to serve as a default listener at the application level. When the framework generates the component tree for a given page (during Restore View or Render Response), any components of type UICommand are registered with this listener. A component that implements the ActionSource interface (for example, UICommand) will queue an ActionEvent when the framework invokes its processDecodes() method. At the end of the Invoke Application phase (or the Apply Request Values phase if the component’s immediate property is set to true), the default ActionListener is responsible for dispatching these events by evaluating the component’s method binding expression to locate an action method that it can then invoke. Action methods must take no arguments and return a string. The default ActionListener passes the string returned from the action method to the framework’s default NavigationHandler. The Navigation Handler in turn looks for a matching navigation rule in the application configuration file. If a matching value is found, the NavigationHandler calls setViewRoot() on the FacesContext with the name of the new view. If no match is found, the current view (and its tree of components) remains unchanged. At the end of the Invoke Application phase (Apply Request Values if immediate was set to true), the framework passes control to the Render Response phase, at which point the current view in the FacesContext is rendered. You can customize the framework’s behavior if desired by substituting your own implementations for the default ActionListener, the default NavigationHandler, or both if you wish, by calling setApplication Listener() or setNavigationHandler() on the application instance as necessary.


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.