JSF Request Handling Lifecycle - DeepakGaikwad.net
Home » JEE, JSF, Tech Notes

JSF Request Handling Lifecycle

7 May 2009 3 Comments

By now you must have understood what is jsf, how to write simple application using jsf, and what are the changes required if you want to use jsp with jsf. In this article, we will try to explore the request processing by jsf. How does it work when we submit a request from client browser?

We need to consider two scenarios here. These scenarios arise because JSF handles first page request from client differently than a post back request(repeat request for same page).

Request Processing for First Request:

The JSF request for a page can be to display an empty page in which a user will enter data. Here, we may not have any event getting fired to retrieve data and plug it in the components. Second important difference is that the view to be rendered, needs to be created for first use. Following diagram explains how all this works.

Handling First Request

  • Create View: Based on requested page, a view is created by constructing a tree of components used in the jsp.
  • Store View in FacesContext: View created in above step is set in FacesContext object so that it can be taken through next stages.
  • Render Response: Nothing else is needed, hence the view is rendered using configured or default HTML renderer.

 Request Processing for Post-back Requests:

This is the second scenario, here the request is sent for a page which has an existing generated view. Here the request contains data entered by user and submitted back to the server. Now the life cycle will need few additional steps to handle this data. Let us see the additional stages we need in above diagram.

Handling Postback Requests

  • Restore View: Taking view id from the input request, in this phase, the FacesServlet retrieves the view (stored at client or server side). This restored view is available for next processing stages.
  • Apply Request Values: Values submitted from client side (mostly user entered values) are converted to required format, and these values are applied to the components in restored view.
  • Process Validations: View components with converted values are input to this stage. In this stage, validations are applied to the values. (Mind you the conversion related validations are already done in Apply Request Values stage.)
  • Update Model Values: Validated values are available in view components as a input to this stage. Further these values are ready to go into the backing beans. This stage sets the values in backing bean by calling appropriate setter method.
  • Invoke Application: This stage invokes action/action listener to get the business processing done.
  • Render Response: Same as first request, in this stage the response is rendered to client using configured or default renderer.

 

More Related Posts in JEE, JSF, Tech Notes

3 Comments »

  • Gertrude said:

    A million thanks for posting this infoarmtoin.

  • Leeladhara said:

    Good Job done…
    Simple and comprehensive explanation..

    Cheers

  • Mogock said:

    Very good explanation

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.

Powered by Sweet Captcha
Verify your real existence,
Drag the dress to the hanger
  • captcha
  • captcha
  • captcha
  • captcha