• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1526
  • Last Modified:

JSTL back and next buttons

I have the following code that gets out information concerning a certain category and sorts them accordingly.

      
      <gc:clips var="clips" categoryId="<%= request.getParameter("categoryId") %>" sort="<%= request.getParameter("sort") %>" />
                  <c:forEach var="clip" items="${clips}">
                                   <c:out value="${clip.title}" />
                                   <c:out value="${clip.thumnail}" />
                        </c:forEach>

What I need to do is build into this back and next buttons for every 20 results.

What is the best way to do this ?

thanks for your time.
0
Eternal_Student
Asked:
Eternal_Student
  • 8
  • 4
1 Solution
 
bloodredsunCommented:
use varStatus and count to control an if statement

               <c:forEach var="clip" items="${clips}" varStatus="status">
                    <c:if test="${status.count > param.start || status.count <= param.end }">
                                   <c:out value="${clip.title}" />
                                   <c:out value="${clip.thumnail}" />
                    </c:if>
                </c:forEach>

then just set the values as request parameters, mypage.jsp?start=20&end=40 via the links assigned to the buttons
0
 
Eternal_StudentAuthor Commented:
Hi bloodredsun, thanks for your help.

Would you be able to show me a full example please, I am very new to all of this!
0
 
Eternal_StudentAuthor Commented:
I tried to put start=0&end=16 in the url string but it still returns all results.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Eternal_StudentAuthor Commented:
Ok I changed it to this:

<c:if test="${status.count >= start && status.count < end}">

Which works now if I change the values in the URL I am just not sure how to calculate and display the back and next buttons.
0
 
bloodredsunCommented:
Just subtract or add the paging value to the start and end request parameters in the link

<a href="thispage.jsp?start=<c:out value='${param.start - 20}'/>&end=<c:out value='${param.end - 20}'/>">Back</a>
<a href="thispage.jsp?start=<c:out value='${param.start + 20}'/>&end=<c:out value='${param.end + 20}'/>"> Forward</a>

You'll also want to add some code so that this so that the back button only shows when there is some results to go back to.
0
 
Eternal_StudentAuthor Commented:
I will also need to do the same for the forward button.

I guess I need to store the actual amount of results somewhere ? how would I get this into a variable ?

i think im getting there, thanks blood.
0
 
Eternal_StudentAuthor Commented:
I realise that:

<c:if test="${param.start > 1}">
  // display previous link
</c:if>

Will cover the previous link but im not sure how I would test ${param.end} against the total amount of results ?

How would this be done ?
0
 
Eternal_StudentAuthor Commented:
I guess my question is .. how would I take the total amount of results and store them in a variable ?
0
 
bloodredsunCommented:
It depends on what the variable clips is: a RowSet, an ArrayList etc. You should be able to work this out pretty easily.
0
 
Eternal_StudentAuthor Commented:
Im not sure which it is and even if I did know im not sure how I would put that value into a variable. I know what I need to do but im not familiar with jsp or jstl so it is over my head at this point in time.
0
 
bloodredsunCommented:
use the c:set tag
0
 
Eternal_StudentAuthor Commented:
Excellent, you are the man.

<c:set var="total" value="${status.count}"/>

then:

<c:if test="${param.end < total}">


Sorry, all I needed was a hint or two [or was it three ?] but I am trying to grasp this the best I can looking at examples. If you know of any JSTL tutorials for absolute dummies please point me in the right direction.

thanks again.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

  • 8
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now