You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Canny Duck <du...@googlemail.com> on 2008/09/15 08:55:54 UTC
[S2] How to prevent validation if type conversion fails
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
Re: [S2] How to prevent validation if type conversion fails
Posted by Gabriel Belingueres <be...@gmail.com>.
I remember having a problem like this before. See the following link:
http://www.nabble.com/-S2--Conversion-validation-issue-td18576772.html#a18576772
2008/9/15 Canny Duck <du...@googlemail.com>:
>
> 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
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org