background image

The Row Interface

<< query Tag Result Interface | JSTL Functions >>
<< query Tag Result Interface | JSTL Functions >>

The Row Interface

</h4>
</c:forEach>
The following excerpt from
tut-install/javaeetutorial5/examples/web/bookstore4/web/books/bookcatalog.jsp uses
the Row interface to retrieve values from the columns of a book row using scripting language
expressions. First, the book row that matches a request parameter (bid) is retrieved from the
database. Because the bid and bookRow objects are later used by tags that use scripting language
expressions to set attribute values and by a scriptlet that adds a book to the shopping cart, both
objects are declared as scripting variables using the jsp:useBean tag. The page creates a bean
that describes the book, and scripting language expressions are used to set the book properties
from book row column values. Then the book is added to the shopping cart.
You might want to compare this version of bookcatalog.jsp to the versions in
Chapter 5,
"JavaServer Pages Technology"
and
Chapter 8, "Custom Tags in JSP Pages"
that use a book
database JavaBeans component.
<sql:query var=
"books"
dataSource=
"${applicationScope.bookDS}">
select * from PUBLIC.books where id = ?
<sql:param value=
"${bid}" />
</sql:query>
<c:forEach var=
"bookRow" begin="0"
items=
"${books.rowsByIndex}">
<jsp:useBean id=
"bid"
type=
"java.lang.String" />
<jsp:useBean id=
"bookRow" type="java.lang.Object[]" />
<jsp:useBean id=
"addedBook" class="database.Book"
scope=
"page" >
<jsp:setProperty name=
"addedBook" property="bookId"
value=
"${bookRow[0]}" />
<jsp:setProperty name=
"addedBook" property="surname"
value=
"${bookRow[1]}" />
<jsp:setProperty name=
"addedBook" property="firstName"
value=
"${bookRow[2]}" />
<jsp:setProperty name=
"addedBook" property="title"
value=
"${bookRow[3]}" />
<jsp:setProperty name=
"addedBook" property="price"
value=
"${bookRow[4])}" />
<jsp:setProperty name=
"addedBook" property="year"
value=
"${bookRow[6]}" />
<jsp:setProperty name=
"addedBook"
property=
"description"
value=
"${bookRow[7]}" />
<jsp:setProperty name=
"addedBook" property="inventory"
value=
"${bookRow[8]}" />
</jsp:useBean>
<% cart.add(bid, addedBook); %>
SQL Tag Library
Chapter 7 · JavaServer Pages Standard Tag Library
221