Details
-
Type:
Improvement
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: Release 1.5.7
-
Component/s: None
-
Labels:
Description
Hi guys,
I had some problems with the DefaultActionBeanPropertyBinder binding correctly with an EnumSet bean. I traced it and found it was a small modification to DefaultActionBeanPropertyBinder. Here is the additional code that will allow for handling EnumSets. It is just a small modification to bindNonNullValue:
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void bindNonNullValue(ActionBean bean,
PropertyExpressionEvaluation propertyEvaluation, List<Object> valueOrValues,
Class targetType, Class scalarType) throws Exception {
Class valueType = valueOrValues.iterator().next().getClass();
// If the target type is an array, set it as one, otherwise set as scalar
if (targetType.isArray() && !valueType.isArray()) {
Object typedArray = Array.newInstance(scalarType, valueOrValues.size());
for (int i = 0; i < valueOrValues.size(); ++i) {
Array.set(typedArray, i, valueOrValues.get(i));
}
propertyEvaluation.setValue(typedArray);
}
else if (Collection.class.isAssignableFrom(targetType)
&& !Collection.class.isAssignableFrom(valueType)) {
Collection collection = null;
if (targetType.isInterface()) {
collection = (Collection) ReflectUtil.getInterfaceInstance(targetType);
}
else if(EnumSet.class.isAssignableFrom(targetType) && Enum.class.isAssignableFrom(scalarType)) {
collection = EnumSet.noneOf(scalarType.asSubclass(Enum.class));
}
else {
collection = (Collection) targetType.newInstance();
}
collection.addAll(valueOrValues);
propertyEvaluation.setValue(collection);
}
else {
propertyEvaluation.setValue(valueOrValues.get(0));
}
}
Cheers, and lovin' Stripes!
@David, could you attach a diff? Thanks!