• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problems with paging i created

 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am having some issues with the paging i created. Most of the time for most pages it works correctly
However on certain pages if you click on the last page link showed on the screen (say we have 1 2 3 4) and i click on page 4
the last of the items are shown but it creates another bunch of page links when it should stop at 4 and go no further.

THe count per page i am using is 24

Below is my servlet, DAO, and jsp file

TIA
John

 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Crossposted: http://forums.sun.com/thread.jspa?threadID=5358615
Please read this: http://faq.javaranch.com/java/BeForthrightWhenCrossPostingToOtherSites
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think this condition is creating the problems.



Here you are setting the count attribute for the second time. And this will hurt you only when the size of products is < 24 i.e. the actual number of records to be shown on each page...
 
John Schretz
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bauke Scholtz wrote:Crossposted: http://forums.sun.com/thread.jspa?threadID=5358615
Please read this: http://faq.javaranch.com/java/BeForthrightWhenCrossPostingToOtherSites



Sorry this is an urgent issue that i really need help on. I figure the more people that see it the better.

Any help would be greatly appreciated. i did not know that crossposting was shunned upon

thanks
john
 
John Schretz
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:I think this condition is creating the problems.



Here you are setting the count attribute for the second time. And this will hurt you only when the size of products is < 24 i.e. the actual number of records to be shown on each page...



The first count i am setting is the count per page iam am using 24

the second is the count of the array

which one should i remove?

Why exactly though would that cause a problem? Is it doubling the size by setting it twice?
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all remove the code which I pointed out then it will run fine.

When you set the attribute for the second time, the value that was set earlier will be removed. This creates problems. Suppose the last page has 12 records. When you set count for the second time, then it will behave as if 12 records should be shown on each page. So the loop in your JSP will run double times. So if 4 page numbers should have been printed, then 8 will be displayed...
 
John Schretz
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:First of all remove the code which I pointed out then it will run fine.

When you set the attribute for the second time, the value that was set earlier will be removed. This creates problems. Suppose the last page has 12 records. When you set count for the second time, then it will behave as if 12 records should be shown on each page. So the loop in your JSP will run double times. So if 4 page numbers should have been printed, then 8 will be displayed...



ok, just trying to fully understand

if i remove the line



then the only count attribute i will be setting is:

int count = settings.getCatItemCount(); // Which is always going to be 24

So you are saying that i should always set the count to 24?

sorry, i just wnat to understand the fix and not just fix it.

thanks very much for the help

John
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes! You are right. If you change the value of count, then the calculation in the jsp

<c:set var="endcount" value="${itemCount / count}" scope="page"/>

will fail. Suppose the size of products is 12 i.e. the last page has 12 records and total there are 96 records. Then total number of pages should be 4. But since you set count to 12, so itemCount / count will be 96 / 12 i.e. 8. So it will display 8 page numbers...
 
John Schretz
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:Yes! You are right. If you change the value of count, then the calculation in the jsp

<c:set var="endcount" value="${itemCount / count}" scope="page"/>

will fail. Suppose the size of products is 12 i.e. the last page has 12 records and total there are 96 records. Then total number of pages should be 4. But since you set count to 12, so itemCount / count will be 96 / 12 i.e. 8. So it will display 8 page numbers...



ok, so is the problem in the jsp or the servlet?
Should i still remove that line?

thanks again
john
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
John just remove that line and then the code will run fine. The problem is in the servlet dude...
 
John Schretz
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:John just remove that line and then the code will run fine. The problem is in the servlet dude...



lol, i hear ya. I dont want to sound stupid, i am new to jsp/ servlets, but have been a core devloper for a few years.
I just want to understand what i am fixing, so i feel i learned something in the process.

Thanks very much for the help.
John
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic