Nitish Kumar wrote:
I think raghavendra is right.
Rivka, your code is working because you are using primitive type int and not
the wrapper type Integer.
In case of primitive type in case of any exception, it gives you a default
value.
Thanks and Regards,
Nitish Kumar
So after small debugging session I found why it works for Integers and
not for dates (at least in my case)
all classes that implment Convertors interface in BeanUtils, have
something like this as implementation of convert() method:
public Object convert(Class type, Object value) {
if (value == null) {
if (useDefault) {
return (defaultValue);
} else {
throw new ConversionException("No value specified");
}
}
if (value instanceof Date) {
return (value);
}
try {
return (Date.valueOf(value.toString()));
} catch (Exception e) {
if (useDefault) {
return (defaultValue);
} else {
throw new ConversionException(e);
}
}
}
In case of the Integer there is pre-load default value and EVEN if
conversion fails during the population phase, it just use is the dafault
value (and you think it's parsed correctly). In the previous example its
a coincidence that Rivka have 0 as default value (it's just the same
value as init value of IntegerConverter).
The strange point is that I didn't find how can I set a default date
value ... if someone knows it, please share this knowledge here.
For sure this is not a big discovery, but I spent a lot of hours to
udnerstand it and I though that this should be described somewhere at
some public place ... that's why I was a bit bitter in my previuos posts
Regards
Borislav
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]