This might be addressed with a few new attributes:
elementsPerPage - the number of rows to display per page
pageNumberParam - the name of the parameter with the current page number
elementsPerPage would be 10 in this case, and pageNumber would start at 1 by
default. You would need some kind of linkage for the user to specify another
page. Perhaps a separate tag for this, a navigation bar tag. The nav bar
would print links to other pages of the result set. When the user clicked on
one of these links, the pageNumber would be updated. The next visit to the
statement tag would execute the same query again. Within the resultSet tag,
if a pageNumber parameter were present, use it to determine which page to seek
to. If a pageNumberParam were not present, then a default of 1 would be
applied.
<jdbc:connection id="conn1">
<jdbc:url>jdbc:odbc:test</jdbc:url>
<jdbc:driver>sun.jdbc.odbc.JdbcOdbcDriver</jdbc:driver>
</jdbc:connection>
<jdbc:statement id="stmt1" conn="conn1">
<jdbc:query><%= query %></jdbc:query>
<jdbc:resultSet id="myRS" loop="true" elementsPerPage="10"
pageNumberParam="pgNum">
<tr>
<td><jdbc:getColumn position="3"/></td>
<td><jdbc:getColumn position="1"/></td>
</tr>
</jdbc:resultSet>
</jdbc:statement>
<jdbc:navbar resultSet="myRS" pageNumberParam="pgNum">
<a href="thisJspPage?pgNum=<%=previous%>">previous</a>
<a href="thisJspPage?pgNum=<%=next%>">next</a>
</jdbc:navbar>
For example, if a request came in with pgNum=4 set, the jdbc:resultSet tag
would seek to 0-based record: elementsPerPage * (pgNum-1). In this case,
10*(4-1) (=30) would be the first record to display. elementsPerPage
iterations through the result set would occur starting from record 30 and
ending with record 39.
The navbar checks if myRs.isLast() to see if the end has been reached. If
not, then a next value is calculated to be pgNum + 1. In this case, 5. A
previous value is calculated as pgNum - 1 or 1 if pgNum <= 1.
I hope this doesn't just confuse things.
-Mark Howell
mark at nullcraft.org
"Ciot, Thierry" wrote:
>
> I would think it is a very useful feature. Right now I am looking at how to
> display rows using a "paging" mechanism (that is, for example, 10 rows at a
> time).
>
> How would you go about doing this with the current tag lib?
>
> With scrollable record set we could have something like:
>
> <jdbc:connection id="conn1">
> <jdbc:url>jdbc:odbc:test</jdbc:url>
> <jdbc:driver>sun.jdbc.odbc.JdbcOdbcDriver</jdbc:driver>
> </jdbc:connection>
>
> <jdbc:statement id="stmt1" conn="conn1">
> <jdbc:query><%= query %></jdbc:query>
> <jdbc:resultSet id="myRS" loop="true" beginat="20" endat="30">
> <tr>
> <td><jdbc:getColumn position="3"/></td>
> <td><jdbc:getColumn position="1"/></td>
> </tr>
> </jdbc:resultSet>
> </jdbc:statement>
>
> What do you think?
>
> Thierry.
>
> -----Original Message-----
> From: Morgan Delagrange [mailto:[EMAIL PROTECTED]]
> Sent: Monday, July 23, 2001 12:05 AM
> To: {[EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: Re: DBTags and scrollable result sets
>
> Ciot, Thierry wrote on 7/20/01 2:38 pm:
>
> >Hi,
> >
> >Is there any plan to add
> >scrollable result sets support
> >in DBTags?
> >
> >Thanks, Thierry.
>
> Nothing definite. :) That specific feature hasn't actually come up as of
> yet, but it does sound like a good one.
>
> Morgan