• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Validation rule for array of objects.

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic