Eternal_Student
asked on
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("cate goryId") %>" 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.
<gc:clips var="clips" categoryId="<%= request.getParameter("cate
<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.
ASKER
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!
Would you be able to show me a full example please, I am very new to all of this!
ASKER
I tried to put start=0&end=16 in the url string but it still returns all results.
ASKER
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.
<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.
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.
<a href="thispage.jsp?start=<
<a href="thispage.jsp?start=<
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.
ASKER
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.
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.
ASKER
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 ?
<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 ?
ASKER
I guess my question is .. how would I take the total amount of results and store them in a variable ?
It depends on what the variable clips is: a RowSet, an ArrayList etc. You should be able to work this out pretty easily.
ASKER
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
<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.
<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