Académique Documents
Professionnel Documents
Culture Documents
JavaServer Faces
Copyright Lund & Bendsen A/S
JSF lifecycle
JSF uses a well defined procedure a lifecycle to analyse a request, organize and process its components and underlying model, and send a response. The lifecycle consists of six well defined processes. Each time a user sends a request to a JSF web application one or more of these processes will be invoked. As a JSF developer you can configure which processes should be invoked.
JavaServer Faces
Copyright Lund & Bendsen A/S
JSF-lifecycle phase
response complete faces request response complete
Restore View
Process Events
Process Validation
Process Events
response complete
response complete
faces response
Render Response
Process Events
Invoke Application
Process Events
phase
JavaServer Faces
Copyright Lund & Bendsen A/S
4 Scenarios
Non-Faces Request Non-Faces Response Non-Faces Request Faces Response Faces Request Non-Faces Response Faces Request Faces Response
JavaServer Faces
Copyright Lund & Bendsen A/S
JavaServer Faces
Copyright Lund & Bendsen A/S
JavaServer Faces
Copyright Lund & Bendsen A/S
Restore View
A view represents all the components on a page (bundled in a component tree). This is represented by an object of type UIViewRoot which is bound to the active FacesContext. This can either be saved client side (in a hidden field) or server side (default). The server saves the view in a session scope, but can persist it to a disc in case of lack of memory or if the user hasnt accessed the page for a long period of time. In the phase Restore View JSF tries to find a view that corresponds to the invoked page. If such a view does not exist a new will be created. The values, event listeners, validators and converters are loaded with their corresponding UI components. In this phase the language settings are initialized. In case of an initial view the created view has no state and JSF skips directly to the phase Render Response. I case of a postback a view will already have been created. JSF uses the state for the existing view to generate its new state and continues to the phase Apply Request Values.
JavaServer Faces
Copyright Lund & Bendsen A/S
JavaServer Faces
Copyright Lund & Bendsen A/S
10
Process Validations
In this phase the components new data is validated. JSF will once more let each component validate it self by envoking validate(), which either uses internal logic to validate with or use registered Validators. If a validation failes JSF will save the error messaage and move directly to the phase Render Response, where the user will se the previous page and possibly the error message. Otherwise the components property will be set to true.
JavaServer Faces
Copyright Lund & Bendsen A/S
11
JavaServer Faces
Copyright Lund & Bendsen A/S
12
Invoke Application
In this phase ActionEvents are processsed as a response to an invocation of an ActionSource (buttons and links). This means both the action defined as receiver on the page form element as well as potential ActionListeners. If an ActionSource control has its immediate property set to true, it will already have been processed in the phase Apply Request Values. This phase will typically control the page flow. This is done be correlating the result of the action-methods with the navigation rules on the JSF configuration (usually facesconfig.xml). The method for this part of the lifecycle is called processApplication() and is invoked just like the other corresponding methods on the UIViewRoot-object.
JavaServer Faces
Copyright Lund & Bendsen A/S
13
Render Response
In this phase JSF makes the web container create a new response based on the page which the Invoke Applicationphase pointed to. Components on the page are updated using the model and rendered on the page based on their respective Renderers. If an error occurred during the conversion or validation the previous page will be loaded and messages containing error statements will be accessible for <message> / <messages>-tags. The JSF-specification requires that the provider provides a default view handler. This is responsible for generating a response as well as build a view corresponding to the phases Restore View and Render Response. It is possible to provide your own view handler if you would rather not base your JSF application on JSP.
JavaServer Faces
Copyright Lund & Bendsen A/S
14
JavaServer Faces
Copyright Lund & Bendsen A/S
15
JavaServer Faces
Copyright Lund & Bendsen A/S
16