• 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

Validation on multiple checkboxes using Struts validator

 
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I'd appreciate it if you pronounced my name correctly. Pinhead, with a silent "H". Petite ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic