Win a copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java this week in the Agile and Other Processes forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
master stewards:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
garden masters:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
gardeners:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Adding new values in Session

 
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 67357
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you replacing the list on every page? If you want to accumulate the values across pages, don't replace the list, augment it.
 
vjy chin
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 67357
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Marshal
Posts: 67357
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Smith Li
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 67357
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
vjy chin
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 can't renounce my name. It's on all my stationery! And hinted in this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!