Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
amma mal
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33696
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Iam new to struts, can you provide me the sample code to write in validate().

Thanks.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic