Previous Section  < Day Day Up >  Next Section

C.5 Request Processing Lifecycle

When JSF view is requested, the components in the view are asked to perform tasks in a certain order, defined as phases of a request processing lifecycle. This section describes the main events for each phase.

C.5.1 Restore View

The requested view is restored from state sent with the request or available on the server, or created if no view state is available. The specification leaves the details up to the implementation, but the components' restoreState() method is called in this phase if the saveState() method was called earlier to save the state. If a new view is created in this phase, at least the UIViewRoot component is created and the processing continues in the Render Response phase.

C.5.2 Apply Request Values

The processDecodes() method is called on the UIViewRoot component, causing the same method to be called recursively on all components in the component tree with the rendered property set to true, which in turn calls the decode( ) method on the component (or its renderer). The decode() method for an input component sets the submittedValue property for the component. For input components with the immediate property set to true, the submitted value is also converted and validated in this phase by calling the validate() method, causing a ValueChangeEvent to be queued if the validated value differs from the previous value and the local value to be set to the converted, validated submitted value. If the submitted value is invalid, an error message is queued and the FacesContext renderResponse() method is called. For a command component, the decode( ) method queues an ActionEvent if the component triggered the request.

At the end of this phase, the broadcast() method of the source components for all events marked to be processed in any phase or in the Apply Request Values phase is called to notify the event handlers. The event handlers may call the FacesContext renderResponse() method, possibly after selecting a new view. If so, the processing continues in the Render Response phase. Alternatively, an event handler may render a response itself and call the FacesContext responseComplete( ) method, in which case the request processing is terminated.

C.5.3 Process Validations

The processValidators() method is called on the UIViewRoot component, causing the same method to be called recursively on all components in the component tree with the rendered property set to true and that were not validated during the Apply Request Values phase, which in turn calls the validate( ) method on the component if its an input component. Calling the validate() method causes a ValueChangeEvent to be queued if the validated value differs from the previous value and the local value to be set to the converted, validated submitted value. If the submitted value is invalid, an error message is queued and the FacesContext renderResponse() method is called.

At the end of this phase, the broadcast() method of the source components for all events marked to be processed in any phase or in the Process Validations phase is called to notify the event handlers. The event handlers may call the FacesContext renderResponse() method, possibly after selecting a new view. If so, the processing continues in the Render Response phase. Alternatively, an event handler may render a response itself and call the FacesContext responseComplete( ) method, in which case the request processing is terminated.

C.5.4 Update Model Values

When this phase is reached, all submitted values have been validated and converted to the appropriate local value data type. The processUpdates() method is called on the UIViewRoot component, causing the same method to be called recursively on all components in the component tree with the rendered property set to true, which in turn calls the updateModel() method on the component if its an input component. Calling the updateModel() method sets the property of the application object the component is bound to, if any, to the component's local value. If the property can't be set, an error message is queued and the FacesContext renderResponse( ) method is called.

At the end of this phase, the broadcast() method of the source components for all events marked to be processed in any phase or in the Update Model Values phase is called to notify the event handlers. The event handlers may call the FacesContext renderResponse() method, possibly after selecting a new view. If so, the processing continues in the Render Response phase. Alternatively, an event handler may render a response itself and call the FacesContext responseComplete( ) method, in which case the request processing is terminated.

C.5.5 Invoke Application

When this phase is reached, all application bean properties bound to input components have been set. The processApplication( ) method is called on the UIViewRoot component, causing the broadcast() method of the source components for all events marked to be processed in any phase or in the Invoke Application phase to be called to notify the event handlers. The event handlers may call the FacesContext renderResponse() method, possibly after selecting a new view. If so, the processing continues in the Render Response phase. Alternatively, an event handler may render a response itself and call the FacesContext responseComplete( ) method, in which case the request processing is terminated.

C.5.6 Render Response

In the phase, the component tree is rendered. The specification only defines the behavior for the JSP presentation layer an leaves the details up to the implementation for other presentation layer technologies. For the JSP layer, the JSP page is processed. If this is the first time the view is rendered, the JSF action elements in the page creates and configures the components they represent and ask them to render themselves by calling the encoding methods; otherwise the components are just asked to render themselves. The components' saveState() method may be called in this phase and the state for the complete tree included in the response—for example, as hidden fields in each HTML form.

    Previous Section  < Day Day Up >  Next Section