News: - Used by 85,000 Members - SMS Backed up 7,35,000 - Contacts Stored  28,850 !!

Main Menu

Life Cycle of JSF Application

Started by thiruvasagamani, Aug 28, 2008, 07:49 PM

Previous topic - Next topic


The life cycle is defined as the processes and phases needs to go through to generate the response for a given request. For JSF, it consists of following six steps that an application follows when any request comes to the system for the processing.

Phase 1: Restore View

A request comes via the FacesServlet controller. It examines the request and extracts the view ID that is determined by the name of the JSP page. The JSF framework controller uses the view ID to look up the components for the current view. If the view doesn't already exist, the JSF controller creates it. If the view already exists, the JSF controller uses it. The view contains all the GUI components. This phase of the lifecycle presents three view instances: new view, initial view, and post back, and each one handled separately.

Phase 2: Apply request values

In this phase each component retrieves its current state. The components are first retrieved or created from the FacesContext object, followed by their values which are typically retrieved from the request parameters, although they can also be retrieved from cookies or headers. If a component's immediate event handling property is not set to true, the values are just converted. So if the field is bound to an Integer property, the value is converted to an Integer but if value conversion fails, an error message is generated and queued in the FacesContext to be displayed in the render response phase.

Phase 3: Process validation

The first event handling of the lifecycle takes place after the apply request values phase. In this stage, each component have its values validated against the application's validation rules. The validation rules can be pre-defined or defined by the developer. Values entered by the user are compared to the validation rules. If an entered value is invalid, an error message is added to FacesContext, and the component is marked invalid. If a component is marked invalid, JSF advances to the render response phase, which will display the current view with the validation error messages.

Phase 4: Update model values

It updates the actual values of the server-side model, by updating the properties of backing beans (also known as managed beans). Only bean properties that are bound to a component's value will be updated. As this phase happens after validation, so the values copied to bean's properties are also valid.

Phase 5: Invoke application

Here the JSF controller invokes the application to handle Form submissions. The component values are converted, validated, and applied to the model objects, so we can now use them to execute the application's business logic. At this phase the next logical view for a given sequence or number of possible sequences are specified by defining a specific outcome for a successful form submission and returning that outcome.
For example: on successful outcome, move the user to the next page. For this navigation, create a mapping to the successful outcome as a navigation rule in the faces-config.xml file. Once the navigation occurs, can move to the final phase of the lifecycle.

Phase 6: Render response

Render Response view with all of its components in their current state are displayed. The application utilizes common JSF GUI components like Radio List, List, Text Field, Label, Panel etc.
Thiruvasakamani Karnan