useSpringBinding bug fix

This commit is contained in:
Keith Donald
2008-09-16 19:23:52 +00:00
parent b0bfb83cc2
commit b90c5b7d85
3 changed files with 29 additions and 3 deletions

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.binding.convert;
import org.springframework.core.style.StylerUtils;
/**
* Thrown when an attempt to execute a type conversion fails.
*
@@ -87,8 +89,8 @@ public class ConversionExecutionException extends ConversionException {
}
private static String defaultMessage(Object value, Class sourceClass, Class targetClass, Throwable cause) {
return "Unable to convert value " + value + " from type '" + sourceClass.getName() + "' to type '"
+ targetClass.getName() + "; reason = '" + cause.getMessage() + "'";
return "Unable to convert value " + StylerUtils.style(value) + " from type '" + sourceClass.getName()
+ "' to type '" + targetClass.getName() + "'; reason = '" + cause.getMessage() + "'";
}
}

View File

@@ -23,6 +23,7 @@ import org.springframework.beans.BeanWrapperImpl;
import org.springframework.beans.BeansException;
import org.springframework.beans.NotReadablePropertyException;
import org.springframework.beans.NotWritablePropertyException;
import org.springframework.binding.convert.ConversionException;
import org.springframework.binding.convert.ConversionExecutor;
import org.springframework.binding.convert.ConversionService;
import org.springframework.binding.expression.EvaluationException;
@@ -135,7 +136,15 @@ public class BeanWrapperExpression implements Expression {
}
public void setAsText(String text) throws IllegalArgumentException {
setValue(converter.execute(text));
try {
Object convertedValue = converter.execute(text);
setValue(convertedValue);
} catch (ConversionException e) {
IllegalArgumentException iae = new IllegalArgumentException("Unable to convert text '" + text + "'");
iae.initCause(e);
throw iae;
}
}
}
}