aspose file tools
The moose likes JSP and the fly likes Maintaining the state of checkbox in pagination Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "Maintaining the state of checkbox in pagination" Watch "Maintaining the state of checkbox in pagination" New topic
Author

Maintaining the state of checkbox in pagination

manish sahni
Ranch Hand

Joined: Sep 09, 2009
Posts: 36

Hello Ranchers,

I have retrieved 10 records/page along with the check boxes in front of each records from the database and also done pagination in it.

The problem i am getting is whenever i select the check box and go to 2nd page and again come back on previous 1st page , the check box state is refreshed and i do not see any checked check boxes.

How can i maintain the state of a check box in pagination??


David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

We have no idea how you're implementing your pagination, whether or not you're going back to the server when you return to a previous page, how the initial state of the checkboxes is determined in the first place, etc.

If you're talking about this:

1) I hit the database and get the first page's results
2) I check some checkboxes
3) I click on the next page and go to the server to get page two
4) I click some checkboxes there as well
5) I click to go back to page one and the boxes I checked are no longer checked

then the problem is obvious: the checkboxes aren't being persisted, and the page is being refreshed, so of course their values are re-initialized. You'd need to either persist the changes when you go to the next page, or Ajax an update when a checkbox state changes, or...

If you're doing the pagination "in-place", i.e. just updating the pagination div, you *could* keep the checkbox states in JavaScript and update them in one shot when you submit the changes.

But with the information given, it's difficult to help.
manish sahni
Ranch Hand

Joined: Sep 09, 2009
Posts: 36

Hi David ,

I am talking about exactly this:-


1) I hit the database and get the first page's results
2) I check some checkboxes
3) I click on the next page and go to the server to get page two
4) I click some checkboxes there as well
5) I click to go back to page one and the boxes I checked are no longer checked

How to persist the changes in checkbox?? any link or help would be appreciable.
Pravin Shirke
Ranch Hand

Joined: Apr 05, 2008
Posts: 146

hi manish,
just store the id's of selected checkboxes in a hidden field as a comma separated value.
hope this helps

[Vipassana] - It is seeing the reality as it is, And not as you want it to be.!!!
SCJP1.5.
subhash kumar
Ranch Hand

Joined: Jul 14, 2010
Posts: 63
If you save the state of check box when user move to page two.
then restore the saved state, when user moves back to the page one.
But
if user move to the page three
then your requirement says you have to save the state of check boxes of both previous pages. ?
if it is so
then you have to decide the depth up to which you maintains that?
Other factor can be like correctness to check the same boxes whose states you have saved
because if records modified ?
take care for these steps.


Subhash Kumar
Attitude is everything
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Maintaining the state of checkbox in pagination
 
Similar Threads
Pagination
Pagination
Pagination
PAGINATION
Pagination