fixe bug in element type for jeremyg

This commit is contained in:
Keith Donald 2009-07-29 21:30:48 +00:00
parent 17dfc8b0fc
commit db487b6d42
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); FieldModel field = mapValues.get(key);
if (field == null) { if (field == null) {
FieldModelContext context = new MapValueContext(key, this); 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); field = new DefaultFieldModel(valueModel, context);
mapValues.put(key, field); mapValues.put(key, field);
} }
@ -293,8 +294,7 @@ public class DefaultPresentationModel implements PresentationModel {
public FieldModelConfiguration formatElementsWith(Formatter<?> formatter) { public FieldModelConfiguration formatElementsWith(Formatter<?> formatter) {
if (!List.class.isAssignableFrom(domainModelClass) || domainModelClass.isArray()) { if (!List.class.isAssignableFrom(domainModelClass) || domainModelClass.isArray()) {
throw new IllegalStateException( throw new IllegalStateException("Field is not a List or an Array; cannot set a element formatter");
"Field is not a List or an Array; cannot set a element formatter");
} }
elementFormatter = formatter; elementFormatter = formatter;
return this; return this;
@ -344,8 +344,11 @@ public class DefaultPresentationModel implements PresentationModel {
// internal helpers // internal helpers
private Class<?> getElementType() { private Class<?> getElementType() {
if (Map.class.isAssignableFrom(property.getPropertyType())) { Class<?> propertyType = property.getPropertyType();
if (Map.class.isAssignableFrom(propertyType)) {
return GenericCollectionTypeResolver.getMapValueReturnType(property.getReadMethod()); return GenericCollectionTypeResolver.getMapValueReturnType(property.getReadMethod());
} else if (propertyType.isArray()) {
return property.getPropertyType().getComponentType();
} else { } else {
return GenericCollectionTypeResolver.getCollectionReturnType(property.getReadMethod()); return GenericCollectionTypeResolver.getCollectionReturnType(property.getReadMethod());
} }