• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get checkboxes from request parameter

 
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am using LazyValidatorForm in my action class. I am using mapped property for checkbox. Lets say i have a question with checkboxes on my form
Example:
Q)What do you own? .car .van .truck
This question has a unique ID which is question1 and the checkboxes are question values qv1, qv2 and qv3
If you check one checkbox car then i get question1{qv1} in the request parameters. i am saving car checkbox to db after saving, when the user comes back and unchecks car checkbox i need to delete it from the db but the problem is if he unchecks the checkbox i am not getting any thing in the request parameters but i expect it to be question1{null}.

Thanks,
 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's how checkboxes work (atleast in IE). You select a checkbox option, the corresponding name=value is included in the request. When its not selected, the 'name' is absent in the query string.

ram.
 
Saathvik Reddy
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ram,

Thanks for your reply but, if i want to delete the checkbox if it is unchecked how would we do it??
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's one way to do it:

When the form is submitted, query the database again to get the old values and put them in another instance of your ActionForm. Then do something like this:


This will work only if ActionForm is in request scope. If it is in request scope, when the form is submitted, a new instance of your Actionform will be created and get{"question1") will still return null even though no "question1" parameter was sent from the form.
[ May 03, 2006: Message edited by: Merrill Higginson ]
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One thing I have done for similar operations is to store the initial values as hidden fields on the JSP. Then you can compare the settings to determine if you need to delete records.

- Brent
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had same problem sometime back.
I copied the array(representing checkboxes) to another hidden array in java script and passed it to action class and that's working fine.
i used the above method for updating my db.
i think this will work for deletion also.
Hope u got the solution.

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic