10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>The</strong> Life Cycle of a <strong>Java</strong>Server Faces Page<br />

312<br />

<strong>The</strong> <strong>Java</strong>Server Faces implementation performs all these tasks as a series of steps in the<br />

<strong>Java</strong>Server Faces request-response life cycle. Figure 10–3 illustrates these steps.<br />

FIGURE 10–3 <strong>Java</strong>Server Faces Standard Request-Response Life Cycle<br />

Faces<br />

Request<br />

Faces<br />

Response<br />

Restore<br />

View<br />

Render<br />

Response<br />

Render<br />

Response<br />

Apply<br />

Requests<br />

Response<br />

Complete<br />

Process<br />

Events<br />

Response<br />

Complete<br />

Process<br />

Events<br />

Invoke<br />

Application<br />

Conversion Errors/<br />

Render Response<br />

Process<br />

Validations<br />

Response<br />

Complete<br />

Process<br />

Events<br />

Response<br />

Complete<br />

Process<br />

Events<br />

Update<br />

Model<br />

Values<br />

Validation/<br />

Conversion Errors/<br />

Render Response<br />

<strong>The</strong> life cycle handles both kinds of requests: initial requests and postbacks. When a user makes<br />

an initial request for a page, he or she is requesting the page for the first time. When a user<br />

executes a postback, he or she submits the form contained on a page that was previously loaded<br />

into the browser as a result of executing an initial request. When the life cycle handles an initial<br />

request, it only executes the restore view and render response phases because there is no user<br />

input or actions to process. Conversely, when the life cycle handles a postback, it executes all of<br />

the phases.<br />

Usually, the first request for a <strong>Java</strong>Server Faces pages comes in as a result of clicking a hyperlink<br />

on an HTML page that links to the <strong>Java</strong>Server Faces page. To render a response that is another<br />

<strong>Java</strong>Server Faces page, the application creates a new view and stores it in the FacesContext<br />

instance, which represents all of the contextual information associated with processing an<br />

incoming request and creating a response. <strong>The</strong> application then acquires object references<br />

needed by the view and calls FacesContext.renderResponse, which forces immediate<br />

rendering of the view by skipping to the “Render Response Phase” on page 316 of the life cycle,<br />

as is shown by the arrows labelled Render Response in the diagram.<br />

Sometimes, an application might need to redirect to a different web application resource, such<br />

as a web service, or generate a response that does not contain <strong>Java</strong>Server Faces components. In<br />

these situations, the developer must skip the rendering phase (“Render Response Phase” on<br />

<strong>The</strong> <strong>Java</strong> <strong>EE</strong> 5<strong>Tutorial</strong> • June 2010

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!