Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validation rule for array of objects.

 
Meera Godse
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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:

<tr><td>Srno.</td><td>Parameter</td><td>Value</td></tr>
<% int i=0; %>
<logic:iterate name="productForm" id="specs" property="specs">
<tr>
<td><%=(++i)%></td>
<td><html:text name="specs" property="param" indexed="true" /></td>
<td><html:text name="specs" property="val" indexed="true" /></td>
</tr>
</logic:iterate>

any help is appreciated. thanks.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Meera Godse
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic