Forums Register Login

Why should an array variable be declared as a Bean

+Pie Number of slices to send: Send
In the below exampl why should the variable bookRow be decalred as a java bean of type Object[] in order for "${bookRow[0]} to work?

<sql:query var="books">
select * from 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.BookDetails" scope="page" >
<jsp:setProperty name="addedBook" property="bookId" value="${bookRow[0]}" />
[ January 27, 2008: Message edited by: Bear Bibeault ]
+Pie Number of slices to send: Send
Whereas in another example below, the varaible bookRow is not defined as a bean of type Map.

<sql:query var="books">
select * from books
</sql:query>

<c:forEach var="book" begin="0" items="${books.rows}">
<tr>
<c:set var="bookId" value="${book.id}" />
+Pie Number of slices to send: Send
I am not really familiar with the JSTL SQL tags. Its a drawback of sticking with the good application architecture or in this case particularly, MVC. However, after looking at your code and using a bit of programming experience, it looks like in the former snippet it is expecting the record as an array. The elements would be in the same sequential order as they were queried. You have to manipulate the record using array index. In the latter, unlike former, it is expecting a bean object so you can manipulate values using appropriate getters instead.
[ January 27, 2008: Message edited by: Adeel Ansari ]
Hot dog! An advertiser loves us THIS much:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1307 times.
Similar Threads
Date and Timestamp comparison
Validator Issue with multiply beans
confused about the usage of JSP tags
jdbc connection in jsp
How to assign ${somevalue} to a bean using jsp:setproperty
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:39:01.