File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Paging in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Paging in JSP" Watch "Paging in JSP" New topic
Author

Paging in JSP

Rajeev Kashyap
Greenhorn

Joined: Sep 07, 2004
Posts: 19
Hi,
I have 50 values those are comimg from database , but I want only 10 values show at a time and a link next. If I click next, I should go to other next 10 values and so on. How can I achieve it. Pls get back to me soon since I am stuck with problem.

Rajeev
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
If you search this forum, you should find that this question is asked all the time. You can find your solution that way.

Eric
Arundhathi Menon
Ranch Hand

Joined: Jan 14, 2004
Posts: 113
U need to fisrt include the jar -pager-taglib.jar in the lib of the WEB-INF folder

Try modifying this piece of code

---------------------------------------
<%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg" %>


<pg ager
items="<%=DataSize %>"
index="<%= index %>"
maxPageItems="<%= maxPageItems %>"
maxIndexPages="<%= maxIndexPages %>"
isOffset="<%= true %>"
export="offset,currentPageNumber=pageNumber"
scope="request">

<pg aram name="style"/>
<pg aram name="position"/>
<pg aram name="index"/>
<pg aram name="maxPageItems"/>
<pg aram name="maxIndexPages"/>

<%
int pagemove=0;
if (offset.intValue()>DataSize){
pagemove=0;
}
else
{
pagemove= offset.intValue();
}

%>


<% if ("top".equals(position) || "both".equals(position)) { %>
<br>
<%
int currpg=pagemove+15;
%>
<font class = "firstlevel" size="2" > DISPLAYING RECORDS  <%=pagemove%>-<%=currpg%>/<%=DataSize%>    

<pg:index>

<pg:first>
<a href="/tas/TimeSheetPageMove.do?pager.offset=<%=0%>"><nobr>[ First ] </nobr></a>
</pg:first>

<pg rev>
<a href="/tas/TimeSheetPageMove.do?pager.offset=<%=pagemove-15%>"><nobr>[ Prev ] </nobr></a>
</pg rev>

<pg:next>

<a href="/tas/TimeSheetPageMove.do?pager.offset=<%=pagemove +15%>"><nobr>[ Next ]  </nobr></a>
</pg:next>

<pg:last>
<a href="/tas/TimeSheetPageMove.do?pager.offset=<%=DataSize-15%> "><nobr>[ Last ] </nobr></a></font>
</pg:last>

</pg:index>

<% } %>

/*************************/
<%

int a = 0;
if(DataSize<=0)
{%>
<TD colspan="10"><font class = "generalfont">  No records to Display</font></TD>
<%}
for (int i = pagemove,
l = Math.min(i + maxPageItems, DataSize);
i < l; i++)
{

%>

<tr>
<% System.out.println(((java.util.Properties)(TimeSheet.toArray()[i])).getProperty("status"));
if(((java.util.Properties)(TimeSheet.toArray()[i])).getProperty("status").equals("APPROVED")) { %>
<td><input name="timeid" type="checkbox" disabled="true" value=<%=((java.util.Properties)TimeSheet.toArray()[i]).getProperty("timeId")%>></td>
<%} else {%>
<td><input name="timeid" type="checkbox" value=<%=((java.util.Properties)TimeSheet.toArray()[i]).getProperty("timeId")%>></td>
<% }%>

<TD><font class = "generalfont">  <%=((java.util.Properties)TimeSheet.toArray()[i]).getProperty("projName") %></font></TD>
<TD><font class = "generalfont">  <%=((java.util.Properties)TimeSheet.toArray()[i]).getProperty("taskName") %></font></TD>
<TD><font class = "generalfont">  <%=((java.util.Properties)TimeSheet.toArray()[i]).getProperty("activity") %></font></TD>
<TD><font class = "generalfont">  <%=((java.util.Properties)TimeSheet.toArray()[i]).getProperty("startTime") %></font></TD>
<TD><font class = "generalfont">  <%=((java.util.Properties)TimeSheet.toArray()[i]).getProperty("endTime") %></font></TD>
<TD><font class = "generalfont">  <%=((java.util.Properties)TimeSheet.toArray()[i]).getProperty("duration") %></font></TD>
<TD><font class = "generalfont">  <%=((java.util.Properties)TimeSheet.toArray()[i]).getProperty("status") %></font></TD>
<TD><font class = "generalfont">  <%=((java.util.Properties)TimeSheet.toArray()[i]).getProperty("date") %></font></TD>
<TD><font class = "generalfont">  <%=((java.util.Properties)TimeSheet.toArray()[i]).getProperty("Comment") %></font></TD>

</tr>

<pg:item>
</pg:item>
<%
}
%>
</pg ager>
-------------------------------------

Hope this is of some help

regards
Menon


SCJP , SCWCD , SCBCD , SCDJWS
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Paging in JSP