aspose file tools*
The moose likes Struts and the fly likes Validation on multiple checkboxes using Struts validator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Validation on multiple checkboxes using Struts validator" Watch "Validation on multiple checkboxes using Struts validator" New topic
Author

Validation on multiple checkboxes using Struts validator

Grishma Dube
Ranch Hand

Joined: Jul 01, 2003
Posts: 275
I am using Struts validator framework for validations on my page.

On one page, I have multiple checkboxes (no. is not fixed). They are generated runtime depending on the no.of records. On click of submit, I need to make sure that, all checkboxes are checked.

If i set that field as "required", its of no use, because even if i'm checkin a single check box among the list, the condition will be true and it will not validate for rest check boxes.

can anyone help me in solving this problem?
Ram Munshi
Ranch Hand

Joined: Aug 09, 2005
Posts: 55
Hi:

I think you can use java script for this thing,while submiting you can use the code given below in javascript function and then submit the form,it would check all the checkboxes,where chk is name of your checkboxes.
Let me know if it helps

if(document.FORMNAME.checkboxes.length){
alert("inside if");
for(i=0; i<document.FORMNAME.checkboxes.length;i++){
document.FORMNAME.checkboxes[i].checked = chk.checked;
}
}


Ram Munshi
sudhakar Tadepalli
Ranch Hand

Joined: Dec 27, 2001
Posts: 130
If you are using Validation framework, you can do this in validation.xml using indexedListProperty="collection". I assume you have a checkboxes as "collection"

Thanks
Grishma Dube
Ranch Hand

Joined: Jul 01, 2003
Posts: 275
Thanx for the reply.

I tried indexedListProperty="collection". But it is not serving my purpose.

My problem is:-

I have a list of records, generated dynamically. So the no.of checkboxes are not fixed. On click of 'submit', I want to make sure that all checkboxes are checked.

I get error if I haven't checked any of the checkboxes but if one checkbox is checked, it is saying 'No validation error'

Pls help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Validation on multiple checkboxes using Struts validator