Life-Cycle Events

   

Requests in JSF applications are fielded by the JSF implementation typically with a controller servlet which in turn executes the JSF life cycle.

The JSF life cycle is shown in Figure 7-1.

Figure 7-1. JSF Life Cycle

graphics/07fig01.jpg


The JSF life cycle consists of the following phases:

  • Restore View

  • Apply Request Values

  • Process Validations

  • Update Model Values

  • Invoke Application

  • Render Response

The Restore View phase recreates the server-side component tree when you revisit a JSF page. The Apply Request Values phase copies request parameters into component submitted values. The Process Validations phase first converts those submitted values and validates the converted value. The Update Model Values phase copies (converted and validated) values to the model, which is typically denoted in JSF pages with value reference expressions, such as:

 

 <h:inputText value="#{user.name}"/> 

The Invoke Application phase invokes action listeners and actions, in that order, for command components. You can register an action listener and an action with a component like this:

 

 <h:commandButton action="#{bean.action}" actionListener="#{bean.listener}".../> 

In that case, the JSF implementation will invoke the bean's listener method followed by the action method.

Finally, the Render Response phase saves state and loads the next view. For JSP-based applications the JSF navigation handler forwards or redirects to another JSP page. Forwarding is the default behavior, but you can specify redirects with the redirect element in a faces configuration file.

Starting with the Apply Request Values phases, events can be created and placed on an event queue during each life-cycle phase. After those phases, the JSF implementation broadcasts queued events to registered listeners. Those events and their associated listeners are the focus of this chapter.

NOTE

graphics/note_icon.gif

Event listeners can affect the JSF life cycle in one of three ways: 1. Let the life cycle proceed normally; 2. Call FacesContext.renderResponse() to skip the rest of the life cycle up to Render Response; 3. Call FacesContext.responseComplete() to skip the rest of the life cycle entirely. See "Immediate Components" on page 292 for an example of using FacesContext.renderResponse().




core JavaServer Faces
Core JavaServer Faces
ISBN: 0131463055
EAN: 2147483647
Year: 2003
Pages: 121

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net