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.

CoreTag Library<br />

204<br />

<br />

...<br />

<br />

For example, the following sets an EL variable named bookID with the value of the request<br />

parameter named Remove:<br />

<br />

To remove an EL variable, you use the remove tag. When the bookstore JSP page<br />

tut-install/javaeetutorial5/examples/web/bookstore4/web/books/bookreceipt.jsp is<br />

invoked, the shopping session is finished, so the cart session attribute is removed as follows:<br />

<br />

<strong>The</strong> value attribute of the set tag can also take a deferred value expression (See “Immediate<br />

and Deferred Evaluation Syntax” on page 148) so that <strong>Java</strong>Server Faces component tags can<br />

access the value at the appropriate stage of the page life cycle.<br />

<strong>Java</strong>Server Faces technology (see Chapter 10, “<strong>Java</strong>Server Faces Technology”) supports a<br />

multiphase life cycle, which includes separate phases for rendering components, validating<br />

data, updating model values, and performing other tasks. What this means is that any<br />

<strong>Java</strong>Server Faces component tags that reference the value set by the set tag must have access to<br />

this value at different phases of the life cycle, not just during the rendering phase. Consider the<br />

following code:<br />

<br />

...<br />

<br />

...<br />

<strong>The</strong> value attribute of the c:set tag uses a deferred value expression, which means that the<br />

bookId variable it references is available not only during the rendering phase of the <strong>Java</strong>Server<br />

Faces life cycle but also during the later stages of the life cycle. <strong>The</strong>refore, whatever value the<br />

user enters into the bookId component tag is updated to the external data object during the<br />

appropriate stage of the life cycle.<br />

If the expression referenced by the value attribute used immediate evaluation syntax then the<br />

bookId variable would be available only when the component is rendered during the render<br />

response phase. This would prevent the value the user enters into the component from being<br />

converted, validated, or updated to the external data object during the later phases of the life<br />

cycle.<br />

Flow ControlTags in the CoreTag Library<br />

To execute flow control logic, a page author must generally resort to using scriptlets. For<br />

example, the following scriptlet is used to iterate through a shopping cart:<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!