The moose likes Struts and the fly likes Validation rule for array of objects. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Validation rule for array of objects." Watch "Validation rule for array of objects." New topic

Validation rule for array of objects.

Meera Godse

Joined: Jan 09, 2007
Posts: 28
I am facing a problem with validator. I intent to use client side validation & I am unable to write the declarations in the validation.xml file for the following:

My form bean has an array as : private Spec[] specs = new Spec[10];
where Spec contains 2 String fields param and value. So on the JSP, i see an array of textboxes for Param and Value. I want to check if value has been entered for atleast one param-value pair. How do i check this using validator ?
in my jsp, they are declared as:

<% int i=0; %>
<logic:iterate name="productForm" id="specs" property="specs">
<td><html:text name="specs" property="param" indexed="true" /></td>
<td><html:text name="specs" property="val" indexed="true" /></td>

any help is appreciated. thanks.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'm afraid the news is not good. While you can define server-side validations for indexed properties using the indexedListProperty attribute in a field stanza of your validation.xml file, it only works for server-side validation and not client-side.

I've usually ended up writing my own client-side validation anyway, because I like to add things like moving the cursor to the field in error, or doing "onblur" validations. I'd suggest that in this case, you just write your own JavaScript validation code.

Consultant, Sima Solutions
Meera Godse

Joined: Jan 09, 2007
Posts: 28
thank you merrill. i will write my own javascript for this case. One more query. Just like we have a rule for validation of 'email' do we have a check to validate the pathname specified for the html:file control ? The form gets submitted even if i enter some junk characters as abc^&*xy
Meera Godse

Joined: Jan 09, 2007
Posts: 28
How do I use struts validator and my own javascript functions at the same time ? Right now because I am using the validator for client-side validations, i write the onsubmit as "return validateFormName(this)". For the checks not included by the struts validator (like the one discussed above), how do i call my own javascript methods ? please help.
I agree. Here's the link:
subject: Validation rule for array of objects.
It's not a secret anymore!