struts-user mailing list archives

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


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

 public Object convertFromString(Map context, String[] values, Class
        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?


Canny Duck
View this message in context:
Sent from the Struts - User mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message