fixe bug in element type for jeremyg

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@1657 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Keith Donald 2009-07-29 21:30:48 +00:00
parent 5b6b05cb5a
commit 595dca1d33
1 changed files with 26 additions and 23 deletions

View File

@ -277,7 +277,8 @@ public class DefaultPresentationModel implements PresentationModel {
FieldModel field = mapValues.get(key);
if (field == null) {
FieldModelContext context = new MapValueContext(key, this);
ValueModel valueModel = new MapValueValueModel(key, getElementType(), (Map) fieldModel.getValue(), context);
ValueModel valueModel = new MapValueValueModel(key, getElementType(), (Map) fieldModel.getValue(),
context);
field = new DefaultFieldModel(valueModel, context);
mapValues.put(key, field);
}
@ -293,8 +294,7 @@ public class DefaultPresentationModel implements PresentationModel {
public FieldModelConfiguration formatElementsWith(Formatter<?> formatter) {
if (!List.class.isAssignableFrom(domainModelClass) || domainModelClass.isArray()) {
throw new IllegalStateException(
"Field is not a List or an Array; cannot set a element formatter");
throw new IllegalStateException("Field is not a List or an Array; cannot set a element formatter");
}
elementFormatter = formatter;
return this;
@ -344,8 +344,11 @@ public class DefaultPresentationModel implements PresentationModel {
// internal helpers
private Class<?> getElementType() {
if (Map.class.isAssignableFrom(property.getPropertyType())) {
Class<?> propertyType = property.getPropertyType();
if (Map.class.isAssignableFrom(propertyType)) {
return GenericCollectionTypeResolver.getMapValueReturnType(property.getReadMethod());
} else if (propertyType.isArray()) {
return property.getPropertyType().getComponentType();
} else {
return GenericCollectionTypeResolver.getCollectionReturnType(property.getReadMethod());
}