Saturday 14 January 2012

JSF 2 Lifecycle





1 Restore View
2 Apply requests Process events
3 Process Validations
4 Update model values Process events
5 Invoke applications Process events
6 Render response





























        

Restore view

RestoreView is the first phase in the JSF  lifecycle. This phase is used for constructing view to display in the front end. Every view has it's own view id and it is stored in the FacesContext's session object. JSF  View is collection of components associated with its current state. There is two types of state saving mechanism,
  1. Server (default)
  2. Client
Default value is server. If you specify state saving method as server, the state of each components will be stored in the server. If it is client, it will be stored in the client side as hidden variables. This value is configured using javax.faces.STATE_SAVING_METHOD parameter name in your web.xml context params as follows:

1.<context-param>
2.<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
3.<param-value>client</param-value>
4.</context-param>

Apply Requests

After the component tree is restored, each component in the tree extracts its new value from the request parameters by using its decode method. The value is then stored locally on the component. If the conversion of the value fails, an error message associated with the component is generated and queued on FacesContext. This message will be displayed during the render response phase, along with any validation errors resulting from the process validations phase.

Process Validations

During this phase, the JavaServer Faces implementation processes all validators registered on the components in the tree. It examines the component attributes that specify the rules for the validation and compares these rules to the local value stored for the component.

Update Model Values 

After the JavaServer Faces implementation determines that the data is valid, it can walk the component tree and set the corresponding server-side object properties to the components' local values. The JavaServer Faces implementation will update only the bean properties pointed at by an input component's value attribute.
If the local data cannot be converted to the types specified by the bean properties, the life cycle advances directly to the render response phase so that the page is rerendered with errors displayed. This is similar to what happens with validation errors.

Invoke Applications

During this phase, the JavaServer Faces implementation handles any application-level events, such as submitting a form or linking to another page.
At this point, if the application needs to redirect to a different web application resource or generate a response that does not contain any JavaServer Faces components, it can call FacesContext.responseComplete.
If the view being processed was reconstructed from state information from a previous request and if a component has fired an event, these events are broadcast to interested listeners.

Render Response 

During this phase, the JavaServer Faces implementation delegates authority for rendering the page to the JSP container if the application is using JSP pages. If this is an initial request, the components represented on the page will be added to the component tree as the JSP container executes the page. If this is not an initial request, the components are already added to the tree so they needn't be added again. In either case, the components will render themselves as the JSP container traverses the tags in the page.

No comments:

Post a Comment