hi, i am trying to validate an integer field (int primitive type) on a POJO (i.e. MyPojo.integer). i have the validation defined in <ActionClass>-<alias>-validation.xml as follows.
... <field name="myPojo.integer"> <field-validator type="required"> <message>Integer is required!</message> </field-validator> </field> ... when the form posts to the action, if the value of <s:textfield name="myPojo.integer"/> is left blank, i keep seeing a java.lang.NoSuchMethodException: MyPojo.setInteger([Ljava.lang.String;). why is struts trying to insert a string into this int field? the field value is "blank" (empty), so i'd expect struts to be smart enough to see this and not try to insert anything and just return back to the form with the validation error. it should be very easy to define the following validation rules: 1. myPojo.integer is required 2. myPojo.integer is an integer however, it is NOT that easy. here's a set of validation rules that i tried and did not succeed. <field name="myPojo.integer"> <!-- this says myPojo.integer is required --> <field-validator type="required"> <message>Integer is required!</message> </field-validator> <!-- this says myPojo has to be a positive integer --> <field-validator type="regex"> <param name="expression"><![CDATA[^\d+$]]></param> <message>Please enter an integer!</message> </field-validator> </field> when i use this set of validation rules, i also observe the same NoSuchMethodException. this time, however, i do NOT see that the validation works (because I do not see the message, Integer is required!). something like the following works, but STILL, i see the NoSuchMethodException thrown if the field's value is left blank. ... <field-validator type="int"> <param name="min">1</param> <param name="max">10</param> <message>Integer must be between ${min} and ${max}, current value is ${myPojo.integer}.</message> </field-validator> ... however, this last validation rule is absolutely the WORST one to use because if the value on the form is left blank, 1) i will see the NoSuchMethoException thrown and 2) if i allow for min=0 and max=10, the validation will never know if the user entered 0 or was the 0 because there was no value! any ideas is appreciated. i already experimented a lot and did not come up with anything that is why this post is rather long. thanks. --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org