Stripes

Handling EnumSets in DefaultActionBeanPropertyBinder

Details

  • Type: Improvement Improvement
  • Status: Resolved Resolved
  • Priority: Major 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!

Activity

Hide
Timothy Stone added a comment - 01/Jun/11 8:07 PM

@David, could you attach a diff? Thanks!

Show
Timothy Stone added a comment - 01/Jun/11 8:07 PM @David, could you attach a diff? Thanks!
Hide
David Bitkowski added a comment - 01/Jun/11 10:11 PM

DefaultActionBeanPropertyBinder patch file

Show
David Bitkowski added a comment - 01/Jun/11 10:11 PM DefaultActionBeanPropertyBinder patch file
Hide
Ben Gunter added a comment - 02/Dec/11 12:46 PM

Thank you. Fixed for 1.5.7.

Show
Ben Gunter added a comment - 02/Dec/11 12:46 PM Thank you. Fixed for 1.5.7.

People

Vote (0)
Watch (1)

Dates

  • Created:
    01/Jun/11 6:09 PM
    Updated:
    02/Dec/11 12:46 PM
    Resolved:
    02/Dec/11 12:46 PM