Java Reference
In-Depth Information
FIGURE 3-1. JavaServer Faces Standard Request-Response Lifecycle
The request-response lifecycle handles two kinds of requests: initial requests and post-
backs. An initial request occurs when a user makes a request for a page for the first time.
A postback request occurs when a user submits the form contained on a page that was
previously loaded into the browser as a result of executing an initial request.
When the lifecycle handles an initial request, it executes only the Restore View and
Render Response phases, because there is no user input or action to process. Conversely,
when the lifecycle handles a postback, it executes all of the phases.
Usually, the first request for a JavaServer Faces page comes in from a client, as a result
of clicking a link or button component on a JavaServer Faces page. To render a response
that is another JavaServer Faces page, the application creates a new view and stores it in
the javax.faces.context.FacesContext instance, which represents all of the
information associated with processing an incoming request and creating a response. The
application then acquires object references needed by the view and calls the FacesCon-
text.renderResponse method, which forces immediate rendering of the view by
skipping to the Render Response phase of the lifecycle, as is shown by the arrows labelled
Render Response in the diagram.
Sometimes, an application might need to redirect to a different web application resource,
such as a web service, or generate a response that does not contain JavaServer Faces com-
ponents. In these situations, the developer must skip the Render Response phase by call-
ing the FacesContext.responseComplete method. This situation is also shown
in the diagram, with the arrows labelled Response Complete.
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 lifecycle to perform any ne-
cessary conversions, validations, and model updates, and to generate the response.
There is one exception to the lifecycle described in this section. When a component's im-
mediate attribute is set to true , the validation, conversion, and events associated with
these components are processed during the Apply Request Values phase rather than in a
later phase.
The details of the lifecycle explained in the following sections are primarily intended for
developers who need to know information such as when validations, conversions, and
events are usually handled and ways to change how and when they are handled. For more
information on each of the lifecycle phases, download the latest JavaServer Faces Spe-
cification documentation from http://jcp.org/en/jsr/detail?id=314 .
Search WWH ::




Custom Search