IDRS Data Paging Tutorial
There are many times when a returned dataset
is too large to be displayed on one page. To fix this a technique
called data-paging is used to break the data up across several pages.
This technique can be wrather difficult to implement. Thankfully
though, the IDRS allows you to implement data-paging simply and easilly.
Here are the advanteges to having the IDRS handle the paging of data :
-
Data is retrieved only once and then cached. This leads to much faster
retrieval of reports.
-
The number of records per page can be given at either deployment time or
at call time by suplying a number of records.
-
There can be multiple paged sets per report.
-
You can still use external objects and share data connections.
-
The links to move to the next and previous pages in the report are automaticly
generated for you.
As you can see, the IDRS has very powerful data paging capabilities.
Why would you want to page multiple sets of data per page? I don't
know, but you might just have to. It's not difficult to implement
data paging in the IDRS either. Our sample will be a simple email
and phone dirrectory. This package contains an SQL script that will
create the table and insert all of the data that we need. Once the
SQL script is run there will be a table of 1000 people with email addresses
and phone numbers (Don't worry, all of the data was randomly generated,
the java program that generated it is included too). Once our page
is finished we will have a fully searchable index of names, phone numbers
and email addresses!
The first part of building our page is to build the RML document that
will be used to generate the final page. If you are unfamiliar with
RML, then please read the beginner's tutorial. This is how our page
will look when it's finished :
These are all the employees that matched the query
ID |
First Name |
Last Name |
Email |
Phone |
129 |
Marc |
Hill |
mhill@somplace.com |
(614)-472-3271 |
132 |
Marc |
Rodrigez |
mrodrigez@somplace.com |
(614)-472-1581 |
134 |
Marc |
Brokavich |
mbrokavich@somplace.com |
(614)-472-7027 |
138 |
Marc |
Venutuda |
mvenutuda@somplace.com |
(614)-472-4683 |
150 |
Marc |
Winters |
mwinters@somplace.com |
(614)-472-2043 |
163 |
Harry |
Johnson |
hjohnson@somplace.com |
(614)-472-9816 |
169 |
Marc |
Brokavich |
mbrokavich@somplace.com |
(614)-472-1377 |
188 |
Marc |
Aldman |
maldman@somplace.com |
(614)-472-8340 |
199 |
Marc |
Venutuda |
mvenutuda@somplace.com |
(614)-472-6846 |
202 |
Marc |
Leberstien |
mleberstien@somplace.com |
(614)-472-3390 |
Previous |
|
|
|
Next |
As you can see, there is a small number of results here with next and
previous tags inserted into the final page. Even though we have the
words "Next" and "Previous" here, we could have anyhting, including an
image or other words for the links. Here is the full source for the
RML :
<head>
<db id="main">
<pagesize><external></pagesize>
<dbname>jdbc:postgresql:samples</dbname>
<sql>
<src>
SELECT * FROM contacts WHERE
(first = ?) OR (last = ?);
</src>
<vartype>string</vartype>
<vartype>string</vartype>
</sql>
</db>
</head>
<body>
<h1>These are all the employees that matched the query</h1><p>
<table>
<tr><td><b>ID</b></td><td><b>First Name</b></td><td><b>Last
Name</b></td><td><b>Email</b></td><td><b>Phone</b></td></tr>
<repeat id="main">
<tr>
<td><field>main.id</field></td>
<td><field>main.first</field></td>
<td><field>main.last</field></td>
<td><field>main.email</field></td>
<td><field>main.phone</field></td>
</tr>
</repeat>
<tr>
<td align="left"><navprev>Previous</navprev></td>
<td></TD><td></TD><td></TD>
<td align="right"><navnext>Next</navnext></td>
</tr>
</table>
</body>
First, lets look at the <head>. Inside
the <head> tag we are using a single <db> to retrieve all of our
data. The first line after the initital <db> tag is a <PageSize>
tag. The <PageSize> tag tells te IDRS that a dataset is going
to be paged. The first thing it does when it sees this tag is it
looks to see if there is already a cached dataset, if there is then it
uses that data. Next it finds out what record to start on and how
many records will be displayed on the page. If there is a number
in the
<PageSize> tag, then the IDRS will use that number. If, as
in this case, <external> is inside the <PageSize> tag then it will
get the information from the calling webpage. How to suply this information
will be covered later. Once the IDRS hits the <PageSize> tag and
the data is already cached, then no more tags inside the <DB> will be
processed.
The rest of the <head> is pretty standard.
There are only two more things that need to be included in order for the
data to be paged, and those two elements are placed in the <body>.
The <body> seems pretty standard. A table
is created and all of the data is printed to this table. After the
<repeat> loop there is one extra row. That row contains <NavPrev>
and <NavNext> tags. These tags tell the IDRS that you want to
generate the proper <a> HTML tags in order to move to the next set of
records or the previous set. If the IDRS is currently on the first
set of data, then the <NavPrev> tags will do nothing and NOTHING between
the <NavPrev> tags will be displayed. If the IDRS is on the last
page of a dataset then the <NavNext> tag will display nothing.
As far as the RML page is concerned, that is all
we have to do. The next step is building the calling form, this is
what it will look like this:
As you can see we can specify the first name or the last name or both.
We can also specify the number of records to be displayed per page.
This is what the source looks like :
First Name : <input name="main_first"><br>
Last Name : <input name="main_last"><br>
Number of records per page : <select name="main_PageSize">
<option value="5">5</option>
<option value="10">10</option>
<option value="20">20</option>
</select>
<input type="hidden" name="main_FirstRecord" value="0">
<input type="hidden" name="main_Reset" value="true">
<input type="submit">
As you can see there are several new fields including
FirstRecord, Reset and PageSize (all associated with 'main' by having 'main_'
begin their names). Each one of these fields has a meaning towords
data paging. main_PageSize tells the IDRS how many records will be
displayed per page. main_FirstRecord will tell the IDRS what record
to start on, you should always set this to zero, but the option is there
if you wish to change it. main_Reset tells the IDRS to throw out
any cached data it might have. This should always be set to true,
or else you may not be working with fresh data.
Now that the RML document has been created and the
form input page has been built, it's time to deploy the system. For
more information about all of the pieces required to deploying the system,
please see the beginners tutorial.
Because I run PostgreSQL, all of these examples use
PostgreSQL syntax for JDBC drivers, remember to replace the driver and
connection information with your own database's information. This
is the information our deployment will entail.
DocID |
DocName |
DocSrc |
DocGroups |
DocVarSrc |
isFile |
DocParams |
DocConns |
5 |
EmpDir |
dir.rml |
2, |
dirvar.html |
false |
main_first:main_last:main_PageSize:main_FirstRecord:main_Reset: |
jdbc:postgresql:samples, |
The above deployment is very simple. for now we will assume that
group 2 is the employees group. Everything else is fairly simple
if you have already read the beginners tutorial. All of the parameters
in DocParams are the names of form input tags in the calling HTML web page.
Now it's time to deploy the document using the deploy tool:
java InsertToIDRS -insgvfpc postgresql.Driver jdbc:postgresql:idrs
webAdmin asdf 5 EmpDir dir.rml 2, dirvar.html <--|
false main_first:main_last:main_PageSize:main_FirstRecord:main_Reset:
jdbc:postgresql:samples,
That will deploy the new email and phone dirrectory search page into
the IDRS!
One exercise to extend this page is to have a smarter query where if
both the first name and the last name fields are there, then to use AND
in the SQL statement instead of OR. This can be done in ether a stored
procedure or an external java class.
Please send comments to mboorshtein@yahoo.com