Flow Control Tags
Flow Control Tags
<c:set var=
"bookId" value="${param.Remove}"/>
To remove an EL variable, you use the remove tag. When the bookstore JSP page
tut-install/javaeetutorial5/examples/web/bookstore4/web/books/bookreceipt.jsp is
invoked, the shopping session is finished, so the cart session attribute is removed as follows:
<c:remove var=
"cart" scope="session"/>
The value attribute of the set tag can also take a deferred value expression (See
) so that JavaServer Faces component tags can
access the value at the appropriate stage of the page life cycle.
JavaServer Faces technology (see
multiphase life cycle, which includes separate phases for rendering components, validating
data, updating model values, and performing other tasks. What this means is that any
JavaServer Faces component tags that reference the value set by the set tag must have access to
this value at different phases of the life cycle, not just during the rendering phase. Consider the
following code:
<c:set var=
"bookId" scope="page" value="#{BooksBean.books}"/>
...
<h:inputText id=
"bookId" value="#{bookId}"/>
...
The value attribute of the c:set tag uses a deferred value expression, which means that the
bookId
variable it references is available not only during the rendering phase of the JavaServer
Faces life cycle but also during the later stages of the life cycle. Therefore, whatever value the
user enters into the bookId component tag is updated to the external data object during the
appropriate stage of the life cycle.
If the expression referenced by the value attribute used immediate evaluation syntax then the
bookId
variable would be available only when the component is rendered during the render
response phase. This would prevent the value the user enters into the component from being
converted, validated, or updated to the external data object during the later phases of the life
cycle.
Flow Control Tags
To execute flow control logic, a page author must generally resort to using scriptlets. For
example, the following scriptlet is used to iterate through a shopping cart:
<%
Iterator i = cart.getItems().iterator();
while (i.hasNext()) {
ShoppingCartItem item =
Core Tag Library
The Java EE 5 Tutorial · September 2007
206