Friday, July 09, 2010

JSF request processing lifecycle in brief

1.      Restore View Phase: For a new/fresh request, this phase creates a component tree starting with the UIViewRoot. For a post back request (a request from a previously generated JSF response), the component tree is restored (when state saving method is client, the tree is de-serialized from the request. When state saving method is server, the tree is restored from the server’s cache).

2.      Apply Request Values Phase: The values held in the request are fetched and set on the appropriate components. At the end of this phase, the component tree has all the value submitted in the request. The server invokes processDecodes() on UIViewRoot and that call trickles down the entire tree invoking the decode() method on each component. ValueHolder and EditableValueHolder components update the component values and AcionSource components queue an ActionEvent for processing in further phases. If immediate attribute is “true”, validation happens at this phase.

3.      Process Validation Phase: All component in the tree convert and validate their values (that was set in step 2). The server invokes processValidators() on the UIViewRoot (and that in-turn recursively invokes processValidators() on each component). Each component’s processValidators() invokes the converter and validators associated with the component.  If a component fails conversion or validation, its valid property is set to false and a FacesMessage is queued (and rendered in render response phase).

4.      Update Model Values Phase: The backing beans are updated with validated values in the component tree. The server invokes processUpdates() on UIViewRoot which invokes processUpdates() on each component. The processUpdates() method of UIInput types will invoke updateModel() which will update the backing bean.

5.      Invoke Application Phase: Any action method or actionListener methods are invoked in this phase. In phase 2 these components would have queued an ActionEvent. The server invokes the processApplication() on UIViewRoot. This method will invoke the broadcast() method on each ActionSource in the component tree for each queued ActionEvent.

6.      Render Response Phase: The encodeXX() method on each component is invoked. Each method uses its renderer to generate response and persist the component state so that it can restored in a future request.

 

No comments: