paging in JSP using logic:iterate

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>
mgoutham22Asked:
Who is Participating?
 
fargoCommented:
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
 
fargoCommented:
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
 
mgoutham22Author Commented:
i Knew that , but I am very much restricted in using the third party tags, Thanks any way.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
fargoCommented:
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
 
mgoutham22Author Commented:
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
 
fargoCommented:
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
 
mgoutham22Author Commented:
The list size is not fixed.
0
 
mgoutham22Author Commented:
List size will be less than or equal to 20 .
0
 
fargoCommented:
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
 
mgoutham22Author Commented:
let me try it
0
 
fargoCommented:
the provided solution by me does work. Points should be awarded to me.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.