• 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Validation on multiple checkboxes using Struts validator

 
Ranch Hand
Posts: 275
  • 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?
 
Ranch Hand
Posts: 55
  • 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;
}
}
 
Ranch Hand
Posts: 130
  • 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
  • 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
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic