JSF Request Handling Lifecycle
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.

- 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.

- 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.









A million thanks for posting this infoarmtoin.
Good Job done…
Simple and comprehensive explanation..
Cheers
Very good explanation
Leave your response!
Subscribe
Subscribe Via Email
Recent Posts
Recent Comments
Tags
Categories
Archives