background image

Restore View Phase

<< JavaServer Faces Implementation | Process Validations Phase >>
<< JavaServer Faces Implementation | Process Validations Phase >>

Restore View Phase

The most common situation is that a JavaServer Faces component submits a request for another
JavaServer Faces page. In this case, the JavaServer Faces implementation handles the request
and automatically goes through the phases in the life cycle to perform any necessary
conversions, validations, and model updates, and to generate the response.
This rest of this section explains each of the life cycle phases using the guessNumber example.
The details of the life cycle explained in this section are primarily intended for developers who
need to know information such as when validations, conversions, and events are usually
handled and what they can do to change how and when they are handled. Page authors don't
necessarily need to know the details of the life cycle.
Restore View Phase
When a request for a JavaServer Faces page is made, such as when a link or a button is clicked,
the JavaServer Faces implementation begins the restore view phase.
During this phase, the JavaServer Faces implementation builds the view of the page, wires event
handlers and validators to components in the view, and saves the view in the FacesContext
instance, which contains all the information needed to process a single request. All the
application's component tags, event handlers, converters, and validators have access to the
FacesContext
instance.
If the request for the page is an initial request, the JavaServer Faces implementation creates an
empty view during this phase and the life cycle advances to the render response phase, during
which the empty view is populated with the components referenced by the tags in the page.
If the request for the page is a postback, a view corresponding to this page already exists. During
this phase, the JavaServer Faces implementation restores the view by using the state information
saved on the client or the server.
The view for the greeting.jsp page of the guessNumber example would have the UIView
component at the root of the tree, with helloForm as its child and the rest of the JavaServer
Faces UI components as children of helloForm.
Apply Request Values Phase
After the component tree is restored, each component in the tree extracts its new value from the
request parameters by using its decode method. The value is then stored locally on the
component. If the conversion of the value fails, an error message associated with the
component is generated and queued on FacesContext. This message will be displayed during
the render response phase, along with any validation errors resulting from the process
validations phase.
In the case of the userNo component on the greeting.jsp page, the value is whatever the user
entered in the field. Because the object property bound to the component has an Integer type,
the JavaServer Faces implementation converts the value from a String to an Integer.
The Life Cycle of a JavaServer Faces Page
Chapter 10 · JavaServer Faces Technology
315