aspose file tools*
The moose likes JSP and the fly likes Adding new values in Session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Adding new values in Session" Watch "Adding new values in Session" New topic
Author

Adding new values in Session

vjy chin
Ranch Hand

Joined: Feb 17, 2005
Posts: 279
I have a jsp page which will display search results. We have pagination and will display 10 records at a time and the resultset will contain 300 records usually.

I have a checkbox for every record and I need to get the selected values of all these 300 records and pass it to another jsp.

What is the best possible way. Currently I am using an arraylist, getting the checked values and putting them in the arraylist and setting the arraylist in session.

But the problem is, suppose the user selects 1 in the first page, clicks next button, selects 2 more in the 2nd time and click the PASS button(to pass the values to another jsp), only the values selected in the first page is there in session.

How can I include the currently selected ones in session.

Any help appreciated.

Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

Are you replacing the list on every page? If you want to accumulate the values across pages, don't replace the list, augment it.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
vjy chin
Ranch Hand

Joined: Feb 17, 2005
Posts: 279
Actually I am using request.getParameterValues to get the values, then set them in session. So if the user clicks previous or next, it will be in session and I add the oncoming values in session.

But the problem is if the user enters PASS button, without clicking next or previous, the values selected in that page will not be in session.

Is there anyway to include them also in session, since I need the arraylist as well as the control to be passed to another jsp.

Thanks
[ June 23, 2006: Message edited by: vjy chin ]
Rudy Rusli
Ranch Hand

Joined: Jun 01, 2006
Posts: 114
Try saving the values to the session every time any of the checkbox is checked. You need a javascript function that will handle each check and then send the checked values back to the page where you do the saving to ArrayList session variable.

~ Rudy ~
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

Originally posted by vjy chin:

But the problem is if the user enters PASS button, without clicking next or previous, the values selected in that page will not be in session.


That sounds like a bug to me. Fix it.
[ June 23, 2006: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

Originally posted by Rudy Rusli:
Try saving the values to the session every time any of the checkbox is checked.


That would mean getting involved with something like Ajax, which if the OP isn't already familiar with, could be a bit of steep learning curve just to solve this problem.
Rudy Rusli
Ranch Hand

Joined: Jun 01, 2006
Posts: 114
I think it can be done with combination of JSP, and some javascript.

Let's say the JSP page is called test1.jsp:



And then you have the javascript funtion that will do this:


You could also have a hidden inline frame if you don't want to refresh test1.jsp and then
do this instead:
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

Originally posted by Rudy Rusli:
I think it can be done with combination of JSP, and some javascript.


Not without refreshing the entire page. Which seems like a not-very-nice thing to do every time the user clicks a check box.

You could also have a hidden inline frame ...


Yeah, but that's a lot more unweildly than just using Ajax -- in fact, that's how "Ajax" used to be done before XmlHttpRequest came along...
[ June 23, 2006: Message edited by: Bear Bibeault ]
vjy chin
Ranch Hand

Joined: Feb 17, 2005
Posts: 279
Thanks for the suggestions.

Its not a bug. Its just that I am not able to add the latest checkbox values in session without refreshing the page.

As you said, just to add into the session, I dont want to refresh the page.

I know you can use AJAX, I just used it once. SO to use it now would not be ideal.

I did finish this, but the solution might be ugly. I am putting all the values in session, but in the page where the user clicks PASS button, the control goes to the javascript, there i am creating an array of the selected options and passing to the next jsp. Since I have the arraylist in session, I will get all those values, and the values selected in the last page will be obtained from the array from javascript. Then I am adding the array into arraylist.
I know its ugly, but is there better way to do this without AJAX. i.e adding the value in session when the user clicks the checkbox without refreshing.

Thanks
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

What is the intention of the PASS button?

Are you giving them the option of skipping one page of the form if they feel it doesn't apply? If so then, why not treat nulls as a value for those fields that get skipped when a user clicks the PASS button?



Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
vjy chin
Ranch Hand

Joined: Feb 17, 2005
Posts: 279
Actually I need the PASS button to get the values selected in this jsp page to transfer the values to another jsp.

Also its not like skipping a form.

Page A calls Page B and in Page B it has to select some values to link back to Page A. So the user will select some values in Page B, then the value is transfered to Page A using PASS button.

Anyways the solution I described before is working now, but still would be great if someone can tell me how to add the current values in session when the user selects the checkbox.

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adding new values in Session
 
Similar Threads
moving values from 1 select box to another
Selecting records in a jsp and displaying selected in another
This interesting problem
Pgination in java
maintain checkbox status while doing pagination