background image

Using the Standard Validators

<< Registering an Action Listener | Validating a Component's Value >>
<< Registering an Action Listener | Validating a Component's Value >>

Using the Standard Validators

The bookcatalog.jsp page uses setPropertyActionListener with two components: the
commandLink
component used to link to the bookdetails.jsp page and the commandButton
component used to add a book to the cart:
<c:forEach items=
"#{bookDBAO.books}" var="book"
varStatus=
"stat">
<c:set var=
"book" scope="request" value="${book}"/>
...
<h:commandLink action=
"#{catalog.details}"
value=
"#{book.title}">
<f:setPropertyActionListener
target=
"#{requestScope.book}" value="#{book}"/>
</h:commandLink>
...
<h:commandButton id=
"add"
action=
"#{catalog.add}" value="#{bundle.CartAdd}">
<f:setPropertyActionListener
target=
"#{requestScope.book}" value="#{book}"/>
</h:commandButton>
<c:remove var=
"book" scope="request"/>
</c:forEach>
As shown in the preceding code, the commandLink and commandButton components are within a
forEach
tag, which iterates over the list of books. The var attribute refers to a single book in the
list of books.
The object referenced by the var attribute of a forEach tag is in page scope. However, in this
case, you need to put this object into request scope so that when the user activates the
commandLink
component to go to bookdetails.jsp or activates the commandButton
component to go to bookcatalog.jsp, the book data is available to those pages. Therefore, the
setPropertyActionListener
tag is used to set the current book object into request scope when
the commandLink or commandButton component is activated.
In the preceding example, the setPropertyActionListener tag's value attribute references the
book
object. The setPropertyActionListener tag's target attribute references the value
expression requestScope.book, which is where the book object referenced by the value
attribute is stored when the commandLink or the commandButton component is activated.
Using the Standard Validators
JavaServer Faces technology provides a set of standard classes and associated tags that page
authors and application developers can use to validate a component's data.
Table 11­7
lists all
the standard validator classes and the tags that allow you to use the validators from the page.
Using the Standard Validators
Chapter 11 · Using JavaServer Faces Technology in JSP Pages
361