Consider the following scenario :

I have a form element "A" that can accept only integers. 
Corresponding to this property, I have a setA(int i) and getA() methods in my 
ActionForm.

When the user enters a non-integer value for "A" and submits it, the ActionServlet 
populates the form and calls the validate method on my form bean
(assuming my form is a validating type).

I want to validate in my ActionForm if the value entered is an Integer and if not i 
want to populate an error message and have the original user
entered text in place.

- When I looked at the Struts code, I understand that when converting this property 
value to an Integer, if it hits a NumberFormatException, Struts
replaces the value with "0" and calls the validate routine. (in BeanUtils.populate, 
ConvertUtils.convert). Is this correct ?

- Since the FormBean is populated before the validate is called on it, it will have 
the value "0" instead of the user entered text. So my validate for
an integer will always succeed. 
- When this form bean gets displayed again, it will display the value "0" instead of 
the user entered text.

Does this mean that such validations SHOULD be done on the client side by way of 
JavaScript (using onBlur, onSubmit etc) ?

Any suggestions ? 

Thanks,

=================
Kishore Subramanian
Agile Software
Off : 408 999 7128
http://www.agilesoft.com
=================

Reply via email to