• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get checkboxes from request parameter

 
Saathvik Reddy
Ranch Hand
Posts: 228
  • 0
  • Mark post as helpful
  • send pies
  • 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,
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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??
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Brent Sterling
Ranch Hand
Posts: 948
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Vijendra Runwal
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • 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.

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic