Sunday, March 25, 2007

JSF Lifecycle

JSF Lifecycle Phases

1. Restore View

- If the request is first visit of page, builds the view of the page, wire event handlers and validator to each component in view and saves view in FacesContext

- If the action is post back, it restores the view which had already been created

2. Apply request values

- Recursively calls decode() on all the components in tree by extracting new values from request

- In case of conversion failure, stacks up error messages in faces context

- If there are any events queued up, notifies the interested listeners

- If any of the components have immediate attribute set to 'true', conversion, validation and events associated with component are done in this phase

- If the redirection to another web app or non-JSF page required, responseComplete() called on FacesContext

- If the validators or listeners call FacesContext’s renderResponse method, the lifecycle skips to render response phase.

3. Process Validations
- Registered validators on components triggered and error messages would be stacked into faces context if there are any validation issues

- If there are any events queued up, notifies the interested listeners

- If the redirection to another web app or non-JSF page required, responseComplete() called on FacesContext

- If the validators or listeners call FacesContext.renderResponse method, the lifecycle skips to render response phase.

4. Update model values phase

- Copies the values to backed bean properties

- In case of conversion issues, lifecycle advances to render response phase

- If the updateModels or listerners call FacesContext.renderResponse method, the lifecycle skips to render response phase.

- If there are any events queued up, notifies the interested listeners.

- If the redirection to another web app or non-JSF app required, responseComplete() called on FacesContext
- Invoke Application Phase

5. Handles the application level events

- If the redirection to another web app or non-JSF app required, responseComplete() called on FacesContext

6. Render Response Phase

- Renders the response

- If there are any validation errors, renders the error messages on page if there are messages tags.

No comments: