Struts/JSP - How would one view multiple database records over severalpages instead of one?

G

Geoff Winsor

Hi,
I am new to struts and JSP and am working on an application that
accesses a database and returns multiple records as DTOs (class name
"Annotation")into an ArrayList.

Within my Action class:

ArrayList resultList=new ArrayList();
resultList= dataAccessObject.getRecords(); // returns an ArrayList of
Annotation" objects

The ArrayList is then placed as an attribute in the session object:

HttpSession session=request.getSession();
session.setAttribute("resultList",resultList);

I then access the ArrayList in the JSP page as:

<logic:iterate id="resultList" name="resultList" scope="session"
type="search.Annotation" >
<td width="70"> <bean:write name="resultList" property="genome"/>(Chr
<bean:write name="resultList" property="chromosome"/>) </td>
<td width="48"> <bean:write name="resultList" property="geneName"/></td>
<td width="120"> <bean:write name="resultList" property="productName"/>
</td>
<td width="83"> <bean:write name="resultList" property="start"/></td>
<td width="50"> <bean:write name="resultList" property="stop"/></td> </tr>
</logic:iterate>

The above code works fine, however several hundred results can be
returned and I would like to view/navigate around 20 of them at a time
(similar to google results). I am familiar with the <html:iterate> tag's
'offset' and 'length' attibutes and am wondering what the best approach
would be to dynamically set this value. I would be open to completely
different approaches to solving this problem as well and appreciate any
suggestions.
Thanks,
Geoff
 
H

Heiner Kücker

Geoff Winsor wrote
Hi,
I am new to struts and JSP and am working on an application that
accesses a database and returns multiple records as DTOs (class name
"Annotation")into an ArrayList.

Within my Action class:

ArrayList resultList=new ArrayList();
resultList= dataAccessObject.getRecords(); // returns an ArrayList of
Annotation" objects

The ArrayList is then placed as an attribute in the session object:

HttpSession session=request.getSession();
session.setAttribute("resultList",resultList);

I then access the ArrayList in the JSP page as:

<logic:iterate id="resultList" name="resultList" scope="session"
type="search.Annotation" >
<td width="70"> <bean:write name="resultList" property="genome"/>(Chr
<bean:write name="resultList" property="chromosome"/>) </td>
<td width="48"> <bean:write name="resultList" property="geneName"/></td>
<td width="120"> <bean:write name="resultList" property="productName"/>
</td>
<td width="83"> <bean:write name="resultList" property="start"/></td>
<td width="50"> <bean:write name="resultList" property="stop"/></td> </tr>
</logic:iterate>

The above code works fine, however several hundred results can be
returned and I would like to view/navigate around 20 of them at a time
(similar to google results). I am familiar with the <html:iterate> tag's
'offset' and 'length' attibutes and am wondering what the best approach
would be to dynamically set this value. I would be open to completely
different approaches to solving this problem as well and appreciate any
suggestions.
Thanks,
Geoff

Search in a search engine for

struts pagination

There is many open source taglibs for this issue.

Heiner Kuecker
Internet: http://www.heinerkuecker.de http://www.heiner-kuecker.de
JSP WorkFlow PageFlow Page Flow FlowControl Navigation: http://www.control-and-command.de
Java Expression Formula Parser: http://www.heinerkuecker.de/Expression.html
CnC Template Technology http://www.heinerkuecker.de/Expression.html#templ
Domain Specific Languages http://www.heinerkuecker.de/DomainParser.html
 
G

Geoff Winsor

Heiner Kücker wrote:

Thanks Heiner,
That was very helpful. I had spent a lot of time searching for this
using other keywords, but with no success.
Cheers,
Geoff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top