Java

Java Server Faces

Java Server Faces technology is a user-interface framework for Java web applications.  It is focused on the view tier of an MVC-based architecture.

mvc

 

 

 

 

 

 

 

 

                                                               MVC Architecture of JSF

Java Server Faces Life Cycle

 

 

jsf_life_cycle1

Restore View: In this phase, the JSF implementation restores the objects and data structures that represent the view of the request. Of course, if this is the client’s first visit to a page, the JSF implementation must create the view. When a JSF implementation creates and renders a JSF-enabled page, it creates UI objects for each view component. The components are stored in a component tree, and the state of the UI view is saved for subsequent requests. If this is a subsequent request, the previously saved UI view is retrieved for the processing of the current request.

Apply Request Values: Any data that was sent as part of the request is passed to the appropriate UI objects that compose the view. Those objects update their state with the data values. Data can come from input fields in a web form, from cookies sent as part of the request, or from request headers. Data for some components, such as components that create HTML input fields, is validated at this time. Note that this does not yet update the business objects that compose the model. It updates only the UI components with the new data.

Process Validations: The data that was submitted with the form is validated (if it was not validated in the previous phase). As with the previous phase, this does not yet update the business objects in the application. This is because if the JSF implementation began to update the business objects as data was validated, and a piece of data failed validation, the model would be partially updated and in an invalid state.

Update Model Values: After all validations are complete, the business objects that make up the application are updated with the validated data from the request. In addition, if any of the data needs to be converted to a different format to update the model (for example, converting a String to a Date object), the conversion occurs in this phase. Conversion is needed when the data type of a property is not a String or a Java primitive.

Invoke Application: During this phase, the action method of any command button or link that was activated is called. In addition, any events that were generated during previous phases and that have not yet been handled are passed to the web application so that it can complete any other processing of the request that is required.

Render Response: The response UI components are rendered, and the response is sent to the client. The state of the UI components is saved so that the component tree can be restored when the client sends another request. For a JSF-enabled application, the thread of execution for a request/response cycle can flow through each phase, in the order listed here and as shown in Figure below. However, depending on the request, and what happens during the processing and response, not every request will flow through all six phases.

 

Tutorial Links

1.  Java Server Faces – Introduction 

2. How to write your own JSF Components

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.