SWF-905 fix

This commit is contained in:
Keith Donald
2008-10-08 14:42:24 +00:00
parent 5d178452b9
commit 63af957f7b
5 changed files with 82 additions and 37 deletions

View File

@@ -7,8 +7,9 @@ import javax.el.PropertyNotFoundException;
import javax.el.PropertyNotWritableException;
import javax.el.ValueExpression;
import org.springframework.binding.convert.ConversionExecutor;
import org.springframework.binding.convert.ConversionException;
import org.springframework.binding.convert.ConversionService;
import org.springframework.core.style.StylerUtils;
import org.springframework.util.Assert;
/**
@@ -50,7 +51,7 @@ class BindingValueExpression extends ValueExpression {
public Object getValue(ELContext context) throws NullPointerException, PropertyNotFoundException, ELException {
Object value = targetExpression.getValue(context);
return conversionService.executeConversion(value, expectedType);
return convertValueIfNecessary(value, expectedType);
}
public boolean isReadOnly(ELContext context) throws NullPointerException, PropertyNotFoundException, ELException {
@@ -59,11 +60,7 @@ class BindingValueExpression extends ValueExpression {
public void setValue(ELContext context, Object value) throws NullPointerException, PropertyNotFoundException,
PropertyNotWritableException, ELException {
Class targetType = targetExpression.getType(context);
if (value != null && targetType != null) {
ConversionExecutor converter = conversionService.getConversionExecutor(value.getClass(), targetType);
value = converter.execute(value);
}
value = convertValueIfNecessary(value, targetExpression.getType(context));
targetExpression.setValue(context, value);
}
@@ -92,4 +89,13 @@ class BindingValueExpression extends ValueExpression {
return targetExpression.hashCode();
}
}
private Object convertValueIfNecessary(Object value, Class expectedType) {
try {
return conversionService.executeConversion(value, expectedType);
} catch (ConversionException e) {
throw new ELException("Unable to coerce value " + StylerUtils.style(value) + " to expected type ["
+ expectedType + "]", e);
}
}
}