Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems with paging i created

 
John Schretz
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • 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

 
Bauke Scholtz
Ranch Hand
Posts: 2458
 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator


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
  • 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: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic