You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Morten Hoey <Mo...@TietoEnator.com> on 2002/09/09 11:35:12 UTC

Struts 1.1b2 Automatic type conversion and validation

Dear List, 

I am having some trouble with using the DynaValidatorForm class. I have
declared one of my form fields as java.lang.Double to make automatic type
conversion. This works fine, but it seems that it takes the validation out
of action. If required validation is set on the field I would expect it to
set an error message in ActionErrors when the field is empty. But that is
not happening; instead the field is set to a default value 0.0.

I have tried to track what happens is seems that the DynaBean class tries to
make a Double.valueOf() on the empty string, this fails and the field is
assigned to a default value 0.0. The field is not empty anymore so it parses
the required test.

The same thing happens if you use a float validation. If you enter 'ABC' in
the field, the value is again set to 0.0, which is a valid float, and it
parses validation.

I think that Validation should be made before trying to make automatic type
conversion. If the validation fails the appropriate error should be set and
the original values should be returned to the user.




Regards, 

Morten T. Høy 
TietoEnator Consulting, 
DENMARK 
  

  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>