• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSTL paging help required

 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,
Im a newbie to web programming and programming in general . I written a web application that requires me to paginate my result set .
Ive implemented this pagination using jstl avoiding the usage of any custom tags.
Ive placed my jsp used to generate pagination in the code below.

The problems that I face currently are --
1. The value generated at point A is automatically typecasted to a floating value and hence the page links are displayed as 1.0,2.0,3.0 etc. I would like to display 1,2,3 instead , anyway I could work around to get that??
2.Secondly , I want to generate links for next page and previous page . But for this , I require the to be available outside the loop for each iteration so that I can use it to calculate my next page and previous page with respect to the current page. Or it would be great if anyone could suggest a method where I could display the next and previous links in the same c:forEach loop but only once rather than for each page
something like <Next>[1] [2]..<Last>
Rather than <Next>[1]<Last><Next>[2]<Last>..

Thanks in Advance.
 
Paul Clapham
Sheriff
Posts: 21875
36
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a <fmt:formatNumber> tag in the JSTL which looks like it's what you need.

Also for your second question, the <c:forEach> tag has a "varStatus" attribute which I believe allows you to check, inside the loop, whether it's the first or last iteration.
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,
Thanks for your reply.
Your first suggestion worked like a breeze ,Thanks!
However , Im facing an issue with the next and previous links,here's how I approach it now.


But when I try this code the 'Previous ' link always points to a value of -pageNum and the 'Next' Link always points to the page beyond the last page . I guess the catch is in finding out how to print 'Next' and 'Previous' only once but take values for the generation of these links dynamically for each iteration.
Can anyone help me with that?
Thanks in advance.
EDIT : it looks like - Previous(Always point s to -pageSize) 1,2,3..,Next(Always points to page after last)
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All ,
I figured a workaround myself.
Retrieved the value from the URL to make things easier
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!