Hi,
I am struggling with something which must be simple - Ive spent a day or so
going through examples but could not find anything covering this !
I want to be able to fill an array of values in my form and use the validator
to ensure they are all of type integer. I am using string arrays since I recall
reading somewhere this is best practise and all the struts examples use string.
I have a select box in a JSP which looks like:
<html:select property="types" multiple="true" size="3" >
<html:option value="1">should work</html:option>
<html:option value="2">should work as well</html:option>
<html:option value="blah">this will fail validation</html:option>
</html:select>
my actionform looks like:
public class PropertyFilter implements Serializable
{
private String[] types;
public String[] getTypes() {
return types;
}
public void setTypes(String[] types) {
this.types = types;
}
}
my validation.xml
<formset>
<form name="PropertyFilterForm">
<field property="types" depends="integer">
<arg0 key="text.validation.type"/>
</field>
</form>
</formset>
Regardless what I fill, even if the values are integer, it fails to pass
validation. According to
http://www.strutskickstart.com/IndexedPropertiesandValidation.ppt#18 I should
do something like:
<field property="types" indexedListProperty="types" depends="integer">
<arg0 key="text.validation.type"/>
</field>
This time, it does indeed check all the values are of type integer, however,
if you do not select anything (the field is not required) the result is:
java.lang.NullPointerException
org.apache.commons.validator.Field.getIndexedProperty(Field.java:796)
org.apache.commons.validator.Field.validate(Field.java:891)
..
Is there an example showing exactly how this should be done anywhere ? - ive
been through all the current and future struts release examples and found
nothing that checks an integer specifically. Could someone comment on the above
to where I am going wrong ?
Thanks,
Tom