JSF Life Cycle

The lifecycle of a JSF application starts with user making a request for a web page and server responding with the page.

JSF specification defines six distinct life cycle phases:

  1. Restore or Build Application View
  2. Apply Request Values
  3. Process Conversions and Validations
  4. Update Model Values
  5. Invoke Application logic
  6. Render Response

The Restore or Build View phase retrieves the component tree for the request page if it was displayed previously otherwise it creates a new component tree if it is being displayed for the first time.

If there are no Request Values, the JSF implementation skips ahead to the Render Response Phase. This happens when the page is displayed for the first time.

Otherwise the next phase is Apply Request Values phase. In this phase the JSF implementation iterates over the Component Objects in the Component Tree. Each Component Object checks which request values belong to it and stores them.

The values stored in the Component Tree are called “Local Values”. On your JSF page you can attach Validators that can validate these “Local Values”. The Validators are executed in the Process Validation Phase. If the Validation passes the JSF life cycle proceeds normally. However if conversion or validation error occurs JSF implementation invokes the Render Response phase directly, re-displaying the current page so that the user has another chance to provide correct inputs.

After the Converters and Validators have done their work it is assumed that it is safe to update the Data Model. During the Update Model Values phase the “Local Values” are used to update the beans that are wired to the Components.

In the Invoke Application Logic Phase the action method of the button or link component that caused the form submission is executed. This method can carryout the application processing logic. It returns an outcome string that is passed to the Navigation Handler. Navigation Handler looks up the next page to be rendered.

Finally the Render Response phase encodes the response and sends it to the browser. When a user submits a form, clicks a link, or otherwise generates a new request, the cycle starts again.

References

http://docs.oracle.com/javaee/6/tutorial/doc/bnaph.html

Advertisements

,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: