Solved

I am displaying all the list in one page right now using jstl. could you please let me know how to display the same using pagination technique,like 10 items in the list in one page. I am not using sql

Posted on 2009-04-14
7
1,080 Views
Last Modified: 2012-05-06
I am displaying all the list in one page right now using jstl. could you please let me know how to display the same using pagination technique,like 10 items in the list in one page. I am not using sql to retrieve this list. I need to display the page using div tag.

Any code samples or ideas would be appreciated.

thanks
Kalam
0
Comment
Question by:kalam_shaik
7 Comments
 
LVL 27

Expert Comment

by:rrz
ID: 24140098
Please show us your JSTL code. Maybe we can work from there.
0
 

Author Comment

by:kalam_shaik
ID: 24140242
Pleease find the snippet of code below used to dispaly the whole list of comments.

<c:if test="${null != blogessay.comments && not empty blogessay.comments}" >
                                                
<h1 class="commentHeader">COMMENTS</h1>
<!-- begin comment (repeat as necessary) -->
      <c:forEach var="comment" items="${blogessay.comments}" varStatus="commentCounter">
            <fmt:parseDate var="dateObj" pattern="yyyy-MM-dd HH:mm:ss.S" value="${comment.lastUpdateDate}" />

<!-- begin comment (repeat as necessary) -->
            <div class="commentDetails">
                  <div class="commenter">
                  <img src="<c:out value="${comment.avatar}" />" alt="" />
                  <div class="label"><c:out value="${comment.userName}" /></div>
            </div>
      <div class="essayComment">
            <span class="bold">POSTED ON:</span> <fmt:formatDate pattern="MMM dd, yyyy hh:mm aaa" value="${dateObj}" /><br />
            <div class="commentActions">
                  <a class="flagit" href="#" onclick='javascript:confirmFlagComment(<c:out value="${comment.ID}" />)'>Flag it</a>
            </div>
      </div>


<div class="commentText">
      <p><c:out value="${comment.commentText}" escapeXml="false" /></p>
</div>
                                          

</div>
<div class="clear"></div>
<c:if test="${!commentCounter.last}" >
</c:if>
<!-- end comment (repeat as necessary) -->
      </c:forEach>
</c:if>

<!-- ***** END comment threads ***** -->
0
 
LVL 11

Expert Comment

by:Manish
ID: 24144934
If you want to write your own, then it is kind of difficult,
but you can use existing tag lib like
http://jsptags.com/tags/navigation/pager/pager-taglib-2.0.html
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 13

Expert Comment

by:Murali Murugesan
ID: 24145527
Use display tag library its very cool with JSTL.
http://displaytag.sourceforge.net/1.2/

a very simple library to play around with.

-Murali*
0
 
LVL 27

Expert Comment

by:rrz
ID: 24149601
karanw and Murali have made good suggestions.   But, if you just want something simple, then you could use something like the test JSP below here.  If you have any troubles or you need to tweak it, then ask us for help.  
<%@ page import="java.util.*" %>

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 

<%

   List<String> comments = Arrays.asList("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");

%>

<c:set var="comments" scope="session" value="<%=comments%>"/>

<c:set var="totalCount" scope="session" value="<%=comments.size()%>"/>

<c:set var="perPage" scope="session"  value="4"/>

<c:forEach var="boundaryStart" begin="0" end="${totalCount - 1}" step="${perPage}">

         <a href="?start=${boundaryStart}">[${boundaryStart} - ${boundaryStart + perPage - 1}]</a>

</c:forEach>

<c:if test="${null != comments && not empty comments}" >                                                

<h1 class="commentHeader">COMMENTS</h1>

   <c:forEach var="comment" items="${comments}" varStatus="commentCounter"

                            begin="${param.start}" end="${param.start + perPage - 1}">

       <div class="commentDetails">

                  <div class="commenter">

                          <div class="label">${comment}</div>

                  </div>

         <div class="essayComment">

            <span class="bold">POSTED ON:</span> <fmt:formatDate pattern="MMM dd, yyyy hh:mm aaa" value="${dateObj}" /><br />

            <div class="commentActions">

                  <a class="flagit" href="#" onclick='javascript:confirmFlagComment(${comment})'>Flag it</a>

            </div>

         </div>

       </div>

   </c:forEach>

</c:if>

Open in new window

0
 

Author Comment

by:kalam_shaik
ID: 24150329
Thanks Karan and Murali. The above code snippet is sufficient for my requirement, but I am trying to make some modifications to the code that so that I can get the list as 1-10 and the button next (>) to display the next 10 items and button to go to previous(<). Please let me know if you have any immediate thoughts to do some thing like this.

just some thing like this 1-10  of 80  : »

thanks,
Kalam
0
 
LVL 27

Accepted Solution

by:
rrz earned 500 total points
ID: 24154588
Here is what I did tonight. If you need more help, then tell us. Maybe I will have more time tomorrow.  
<%@ page import="java.util.*" %>

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 

<%

   List<String> comments = Arrays.asList("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");

%>

<c:set var="comments" scope="session" value="<%=comments%>"/>

<c:set var="totalCount" scope="session" value="<%=comments.size()%>"/>

<c:set var="perPage" scope="session"  value="10"/>

<c:set var="pageStart" value="${param.start}"/>

<c:if test="${empty pageStart or pageStart < 0}">

       <c:set var="pageStart" value="0"/>

</c:if>

<c:if test="${totalCount < pageStart}">

       <c:set var="pageStart" value="${pageStart - 10}"/>

</c:if>

        <a href="?start=${pageStart - 10}"><<</a>${pageStart + 1} - ${pageStart + 10} <a href="?start=${pageStart + 10}">>></a>

<c:if test="${null != comments && not empty comments}" >                                                

<h1 class="commentHeader">COMMENTS</h1>

   <c:forEach var="comment" items="${comments}" varStatus="commentCounter"

                            begin="${pageStart}" end="${pageStart + perPage - 1}">

       <div class="commentDetails">

                  <div class="commenter">

                          <div class="label">${comment}</div>

                  </div>

         <div class="essayComment">

            <span class="bold">POSTED ON:</span> <fmt:formatDate pattern="MMM dd, yyyy hh:mm aaa" value="${dateObj}" /><br />

            <div class="commentActions">

                  <a class="flagit" href="#" onclick='javascript:confirmFlagComment(${comment})'>Flag it</a>

            </div>

         </div>

       </div>

   </c:forEach>

</c:if>

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
handling Struts tag, JSTL tag and scriptlet in Ajax. 7 170
love6 challenge java 31 129
struts exact match support 3 51
spring JDBC Template example error 26 206
With more and more people tethered to the internet, advertisers can reach you in new and creative ways. Push notifications on your smartphone, customized advertisements based on your previous searches, and email inboxes filled with promotional pitch…
Note: This is the third blog post in a series on email clearinghouses (https://www.xmatters.com/alert-management/blog-email-has-failed-us?utm_campaign=70138000000ydLoAAI&utm_source=exex&utm_medium=article&utm_content=blog-post).   We’ve been talki…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

943 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now