wood burning stoves 2.0*
The moose likes Servlets and the fly likes Problems with paging i created Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problems with paging i created" Watch "Problems with paging i created" New topic
Author

Problems with paging i created

John Schretz
Ranch Hand

Joined: Sep 10, 2008
Posts: 188
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

Joined: Oct 08, 2006
Posts: 2458
Crossposted: http://forums.sun.com/thread.jspa?threadID=5358615
Please read this: http://faq.javaranch.com/java/BeForthrightWhenCrossPostingToOtherSites
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
John Schretz
Ranch Hand

Joined: Sep 10, 2008
Posts: 188


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

Joined: Sep 10, 2008
Posts: 188
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

Joined: Aug 03, 2008
Posts: 9291
    
  17

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

Joined: Sep 10, 2008
Posts: 188
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

Joined: Aug 03, 2008
Posts: 9291
    
  17

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

Joined: Sep 10, 2008
Posts: 188
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

Joined: Aug 03, 2008
Posts: 9291
    
  17

John just remove that line and then the code will run fine. The problem is in the servlet dude...
John Schretz
Ranch Hand

Joined: Sep 10, 2008
Posts: 188
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problems with paging i created
 
Similar Threads
Unable to find specific product
xml from jsp
pagination exception in spring
quick paging calculation question
How to paging?NumberFormatException: For input string: "pageStr"