File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validation on multiple checkboxes using Struts validator

 
Grishma Dube
Ranch Hand
Posts: 275
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
}
}
 
sudhakar Tadepalli
Ranch Hand
Posts: 130
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 275
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic