struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Canny Duck <duckmai...@googlemail.com>
Subject [S2] How to prevent validation if type conversion fails
Date Mon, 15 Sep 2008 06:55:54 GMT

Hi,

I wrote I type converter that convert a Date into a String:

...
 public Object convertFromString(Map context, String[] values, Class
toClass)
 {
        if (values != null && values.length > 0 && values[0] != null &&
values[0].length() > 0) {
            SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
            try {
                return sdf.parse(values[0]);
            } catch (ParseException e) {
                throw new TypeConversionException(e);
            }
        }
        return null;
 }
...

If the type conversion fails the convert()-method returns a null value.
After the type conversation I validate the field and check that this is not
null. So if the field value is "dfasde3" I get a type converion error and a
null validation error thrown by the Validation framework. So on view site I
have two error messages.

How can I prevent, that the validation for the field is also executed when
the conversion failed?

Thanks

Canny Duck
-- 
View this message in context: http://www.nabble.com/-S2--How-to-prevent-validation-if-type-conversion-fails-tp19487978p19487978.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message