File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Need help for Check Box Validation in struts1.2 without using javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Need help for Check Box Validation in struts1.2 without using javascript " Watch "Need help for Check Box Validation in struts1.2 without using javascript " New topic
Author

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

amma mal
Greenhorn

Joined: Apr 15, 2009
Posts: 10
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30369
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
amma mal
Greenhorn

Joined: Apr 15, 2009
Posts: 10
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

Joined: Apr 15, 2009
Posts: 10
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Apr 15, 2009
Posts: 10
Iam new to struts, can you provide me the sample code to write in validate().

Thanks.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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
 
subject: Need help for Check Box Validation in struts1.2 without using javascript