?
Solved

paging in JSP using logic:iterate

Posted on 2006-04-05
14
Medium Priority
?
3,674 Views
Last Modified: 2008-01-09
I need program for paging in JSP using logic:iterate and struts ,and <b><h3> do not want to use the third party tags </b></h3>
0
Comment
Question by:mgoutham22
  • 6
  • 5
11 Comments
 
LVL 11

Accepted Solution

by:
fargo earned 2000 total points
ID: 16386509
u can make use of pager taglibrary
http://jsptags.com

Check out the site documentation for setting up etc...

following is the ex. template
<%@ page contentType="text/html;charset=ISO-8859-1" language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/pager-taglib.tld" prefix="pg" %>

<!-- Making use of page tag library -->
<pg:pager maxIndexPages="25" maxPageItems="20" export="currentPageNumber=pageNumber">
  <pg:param name="pg"/>
  <pg:param name="q"/>

<center>
<logic:present name="someList">
<logic:notEmpty name="someList">
    <logic:iterate id="element" name="someList">
      <pg:item>
      <tr><td>...</td><td></td> ........</tr>
      <tr><td>...</td><td></td> ........</tr>
      <tr><td>...</td><td></td> ........</tr>
      ......
      </pg:item>
       </logic:iterate>
    </logic:notEmpty>
<logic:empty name="someList" >
.....
</logic:empty>
</logic:present>
</table>
</center>
<br />
<center>
<!-- this is for page indexing ** starts here**-->
  <pg:index>
    <font face=Helvetica size=-1 color=ActiveCaption>Result Pages:
    <pg:prev>&nbsp;<a href="<bean:write name="pageUrl" />" style="text-decoration:none">[&lt;&lt; Prev]</a></pg:prev>
    <pg:pages><%
      if (pageNumber.intValue() < 10) {
        %>&nbsp;<%
      }
      if (pageNumber == currentPageNumber) {
        %><b><%= pageNumber %></b><%
      } else {
        %><a href="<bean:write name="pageUrl" />" style="text-decoration:none"><%= pageNumber %></a><%
      }
    %>
    </pg:pages>
    <pg:next>&nbsp;<a href="<bean:write name="pageUrl" />" style="text-decoration:none">[Next &gt;&gt;]</a></pg:next>
    <br></font>
  </pg:index>
</pg:pager>
</center>
</body>
</html:html>
0
 
LVL 11

Expert Comment

by:fargo
ID: 16386518
You can have a look here
http://www.experts-exchange.com/Web/Web_Languages/JSP/Q_21777860.html

i helped someone to get it done. Please go thru it and let us know if u face problems.
0
 

Author Comment

by:mgoutham22
ID: 16386707
i Knew that , but I am very much restricted in using the third party tags, Thanks any way.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:fargo
ID: 16386733
Then best bet is to have a database based paging. In mysql u can make use of LIMIT clause and in Oracle you can make use of rownum.
0
 

Author Comment

by:mgoutham22
ID: 16386767
ok here is the the complete situation, I have a arraylist size is 20 and need to display 5 a page . it is not some thing related to the database.

I need to write a program using the logic iterate and struts action class.
0
 
LVL 11

Expert Comment

by:fargo
ID: 16386828
ok. for such a small list..u don't really need db. try with the following
1st page
<logic:iterate id="element" name="someList" offset="1" length="5">
...
</logic:iterate>

2nd page
<logic:iterate id="element" name="someList" offset="6" length="5">
...
</logic:iterate>
and -.....

generate the pager links...and add offset as parameter to make a generalise handling.
0
 

Author Comment

by:mgoutham22
ID: 16386915
The list size is not fixed.
0
 

Author Comment

by:mgoutham22
ID: 16386938
List size will be less than or equal to 20 .
0
 
LVL 11

Expert Comment

by:fargo
ID: 16390182
there is no handling with the list size. Why do u have doubts with list size? Only thing we did is set the offset and length to display till 5.
0
 

Author Comment

by:mgoutham22
ID: 16391121
let me try it
0
 
LVL 11

Expert Comment

by:fargo
ID: 16762033
the provided solution by me does work. Points should be awarded to me.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Currently, there is an issue with being able to copy values from an external application to a dropdown list in Project Web Access (PWA).  The standard copy and paste methods don't seem to work properly. Here is a way to accomplish this task to s…
Applications for our next round of the Experts Exchange Scholarship Contest are starting to roll in. It made us wonder what our past winners are up to these days. Here's a look at what four winners experienced with the contest and what they're doing…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question