• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts Validation of options box (java.lang.String[])

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using struts and the ValidatorPlugIn. I am having some issues trying to validate input for an options box. I have the validation working correctly if within the struts-config.xml file the form-property type="java.lang.String" (I can validate the form-property value in the example listed below).

My issue is that I can't validate when the form-property is of type="java.lang.String[]" (I can't validate the form-property assets in the example listed below). Do I need to include something in the validation.xml that indicates I am working with type="java.lang.String[]"

ca_search.jsp (snippets):

<html:form action="/caSearch" target="main" onsubmit="return validateCaSearchForm(this);">

<html:select size="3" property="assets" style="news" multiple="true">
<html ptions collection="assetTypes" property="property" labelProperty="labelProperty"/>
</html:select>

<html:javascript formName="caSearchForm"/>


struts-config.xml:

<form-bean name="caSearchForm" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="assets" type="java.lang.String[]" />
<form-property name="value" type="java.lang.String" />
<form-property name="sites" type="java.lang.String" />
<form-property name="searchFor" type="java.lang.String" />
<form-property name="sortBy" type="java.lang.String" />
<form-property name="departments" type="java.lang.String" />
<form-property name="action" type="java.lang.String" />
</form-bean>


validation.xml:

<form name="caSearchForm">
<field property="value" depends="required">
<arg0 key="ca_search.val"/>
</field>
<field property="assets" depends="required">
<arg0 key="ca_search.assets"/>
</field>
</form>


Again, I have the validation working correctly when form-property is of type="java.lang.String". I can't however validate when the form-property is of type="java.lang.String[]".
 
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try using the "indexedListProperty" of the field attribute.

Extract from validator DTD file:


<!--
The "field" element defines the properties to be validated. In a
web application, a field would also correspond to a control on
a HTML form. To validate the properties, the validator works through
a JavaBean representation. The field element can accept up to 4
attributes:

property The property on the JavaBean corresponding to this
field element.

depends The comma-delimited list of validators to apply against
this field. For the field to succeed, all the
validators must succeed.

page The JavaBean corresponding to this form may include
a page property. Only fields with a "page" attribute
value that is equal to or less than the page property
on the form JavaBean are processed. This is useful when
using a "wizard" approach to completing a large form,
to ensure that a page is not skipped.
[0]

indexedListProperty
The "indexedListProperty" is the method name that will
return an array or a Collection used to retrieve the
list and then loop through the list performing the
validations for this field.

-->



validation.xml change:


Sheldon Fernandes
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic