I've explored the DataBinder and BeanWrapper source a bit...
Unfortunately the current implementation of the DataBinder swallows the original exception cause coming from a PropertyEditor (through the BeanWrapper).
The relevant source snippet is quoted below (spring 1.1.2):
(DataBinder.java, lines 312-326)
Code:
try {
// bind request parameters onto params, ignoring unknown properties
this.errors.getBeanWrapper().setPropertyValues(pvs, true);
}
catch (PropertyAccessExceptionsException ex) {
PropertyAccessException[] exs = ex.getPropertyAccessExceptions();
for (int i = 0; i < exs.length; i++) {
// create field with the exceptions's code, e.g. "typeMismatch"
String field = exs[i].getPropertyChangeEvent().getPropertyName();
this.errors.addError(
new FieldError(this.errors.getObjectName(), field, exs[i].getPropertyChangeEvent().getNewValue(), true,
this.errors.resolveMessageCodes(exs[i].getErrorCode(), field),
getArgumentsForBindingError(field), exs[i].getLocalizedMessage()));
}
}
The PropertyAccessExceptions coming from the BeanWrapper have a cause property (derived form Throwable).
However, this piece of information is not stored in the FieldError instance created.
All FieldErrors caused by PropertyEditor exceptions are coded as "typeMismatch", since BeanWrapperImpl#doTypeConversionIfNecessary() translates all IllegalArgumentExceptions to TypeMismatchExceptions.
I'm quite curious how Spring's claim of being able to "do away with ActionForms and bind to your domain model" works out for others.
Having built quite a number of enterprise applications, I know that there are quite a number of failure paths for translating an String id to a live domain object instance.
How can I bind to a rich domain model other then by using PropertyEditors?
How can I use PropertyEditors if I can't differentiate between various, distinct, potential failures?