• 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

Need help for Check Box Validation in struts1.2 without using javascript

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I need help for validating check box in struts validation without using javascript.
when I click the submit button atleast one check box should be selected. Can anyone help me how to define in validation XML,
how to do it with requiredif and validatewhen conditions, in my jsp page we have 10 checkboxes.
Please let me know if you have any solution for this. it should be server side validation

Thanks in advance,
sairam.
 
author & internet detective
Posts: 41905
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

Did you know we have a forum just for Struts questions? I'll move this for you. The forum software will magically link this post to the move so you can just click it.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can do this by making the property name for each checkbox the same or by using the html:multibox tag. Then you can simply use the "required" validation to verify that at least one checkbox was checked.
 
amma mal
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for reply merill,

here is my JSP code, I cannot use same property ames for each check box

<bean:message key="SubForm.ProgramType.title"/></legend>
<div class="fieldset">
<table width="99%" border="0" cellspacing="5" cellpadding="0">
<tbody>
<tr>
<td>
<html:multibox name="Form" property="Information.s1" styleId="newForm.Information.s1" value="Y"/>
<html:hidden name="newForm" property="Information.s1" value="N"/>
<label style="float: none;" for="newForm.Information.s1" id="newForm.Information.s1.label"><bean:message key="subForm.s1.prompt"/></label>
</td>
<td>
<html:multibox name="newForm" property="Information.s2" styleId="newForm.Information.s2" value="Y"/>
<html:hidden name="newForm" property="Information.s2" value="N"/>
<label style="float: none;" for="newForm.Information.s2" id="newForm.Information.s2.label"><bean:message key="Information.s2.prompt"/></label>
</td>
<td>
<html:multibox name="newForm" property="Information.s3" styleId="newForm.Information.s2" value="Y"/>
<html:hidden name="newForm" property="Information.s2" value="N"/>
<label style="float: none;" for="newForm.Information.s2" id="newForm.Information.s2.label"><bean:message key="SubForm.s2.ompt"/></label>
</td>
</tr>
</tbody>
</table>

any suggestion,please help me.

Thanks,
AMMA.
 
amma mal
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,

Its very urgent, can you help me for checkbox validation. I my JSP I cannot change the checkbox property names ,because all properties are having with different names, any suggestions.

Thanks.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Either use validwhen and construct the expression so at least once checkbox is required (or whatever your requirement is) or do it on the Java side in a validate() method.
 
amma mal
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Iam new to struts, can you provide me the sample code to write in validate().

Thanks.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Searching the web should provide *numerous* examples; it's a simple matter of checking the form properties in question and adding an error if the proper conditions aren't met. IIRC this can be combined with XML validation by calling super.validate() as well.
reply
    Bookmark Topic Watch Topic
  • New Topic