forNestedType usage clarification
This commit is contained in:
parent
c309ef74d7
commit
c6c782df59
|
|
@ -935,7 +935,7 @@ public class BeanWrapperImpl extends AbstractPropertyAccessor implements BeanWra
|
|||
oldValue = Array.get(propValue, arrayIndex);
|
||||
}
|
||||
Object convertedValue = convertIfNecessary(propertyName, oldValue, pv.getValue(), requiredType,
|
||||
PropertyTypeDescriptor.forNestedType(requiredType, new MethodParameter(pd.getReadMethod(), -1), pd));
|
||||
PropertyTypeDescriptor.forNestedType(requiredType, new MethodParameter(pd.getReadMethod(), -1, tokens.keys.length), pd));
|
||||
Array.set(propValue, arrayIndex, convertedValue);
|
||||
}
|
||||
catch (IndexOutOfBoundsException ex) {
|
||||
|
|
@ -953,9 +953,8 @@ public class BeanWrapperImpl extends AbstractPropertyAccessor implements BeanWra
|
|||
if (isExtractOldValueForEditor() && index < list.size()) {
|
||||
oldValue = list.get(index);
|
||||
}
|
||||
// TODO method parameter nesting level should be token.keys.length + 1
|
||||
Object convertedValue = convertIfNecessary(propertyName, oldValue, pv.getValue(), requiredType,
|
||||
PropertyTypeDescriptor.forNestedType(requiredType, new MethodParameter(pd.getReadMethod(), -1), pd));
|
||||
PropertyTypeDescriptor.forNestedType(requiredType, new MethodParameter(pd.getReadMethod(), -1, tokens.keys.length), pd));
|
||||
if (index < list.size()) {
|
||||
list.set(index, convertedValue);
|
||||
}
|
||||
|
|
@ -994,7 +993,7 @@ public class BeanWrapperImpl extends AbstractPropertyAccessor implements BeanWra
|
|||
// TODO method parameter nesting level should be token.keys.length + 1
|
||||
Object convertedMapValue = convertIfNecessary(
|
||||
propertyName, oldValue, pv.getValue(), mapValueType,
|
||||
PropertyTypeDescriptor.forNestedType(mapValueType, new MethodParameter(pd.getReadMethod(), -1), pd));
|
||||
PropertyTypeDescriptor.forNestedType(mapValueType, new MethodParameter(pd.getReadMethod(), -1, tokens.keys.length), pd));
|
||||
map.put(convertedMapKey, convertedMapValue);
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -153,6 +153,18 @@ public class NumberFormattingTests {
|
|||
assertEquals("2,35.00", binder.getBindingResult().getFieldValue("patternList[1]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testPatternList2Formatting() {
|
||||
MutablePropertyValues propertyValues = new MutablePropertyValues();
|
||||
propertyValues.add("patternList2[0]", "1,25.00");
|
||||
propertyValues.add("patternList2[1]", "2,35.00");
|
||||
binder.bind(propertyValues);
|
||||
assertEquals(0, binder.getBindingResult().getErrorCount());
|
||||
assertEquals("1,25.00", binder.getBindingResult().getFieldValue("patternList[0]"));
|
||||
assertEquals("2,35.00", binder.getBindingResult().getFieldValue("patternList[1]"));
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static class TestBean {
|
||||
|
|
@ -175,8 +187,11 @@ public class NumberFormattingTests {
|
|||
private BigDecimal[] patternArray;
|
||||
|
||||
@NumberFormat(pattern="#,##.00")
|
||||
private List[] patternList;
|
||||
private List<BigDecimal>[] patternList;
|
||||
|
||||
@NumberFormat(pattern="#,##.00")
|
||||
private List<BigDecimal> patternList2;
|
||||
|
||||
public Integer getNumberDefault() {
|
||||
return numberDefault;
|
||||
}
|
||||
|
|
@ -225,13 +240,22 @@ public class NumberFormattingTests {
|
|||
this.patternArray = patternArray;
|
||||
}
|
||||
|
||||
public List[] getPatternList() {
|
||||
public List<BigDecimal>[] getPatternList() {
|
||||
return patternList;
|
||||
}
|
||||
|
||||
public void setPatternList(List[] patternList) {
|
||||
public void setPatternList(List<BigDecimal>[] patternList) {
|
||||
this.patternList = patternList;
|
||||
}
|
||||
|
||||
public List<BigDecimal> getPatternList2() {
|
||||
return patternList2;
|
||||
}
|
||||
|
||||
public void setPatternList2(List<BigDecimal> patternList2) {
|
||||
this.patternList2 = patternList2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -136,11 +136,11 @@ public class TypeDescriptor {
|
|||
* Create a new type descriptor for a nested type declared on an array, collection, or map-based method parameter.
|
||||
* Use this factory method when you've resolved a nested source object such as a collection element or map value and wish to have it converted.
|
||||
* @param nestedType the nested type
|
||||
* @param parentMethodParameter the parent method parameter declaring the collection or map
|
||||
* @param methodParameter the method parameter declaring the collection or map
|
||||
* @return the nested type descriptor
|
||||
*/
|
||||
public static TypeDescriptor forNestedType(Class<?> nestedType, MethodParameter parentMethodParameter) {
|
||||
return new TypeDescriptor(nestedType, parentMethodParameter);
|
||||
public static TypeDescriptor forNestedType(Class<?> nestedType, MethodParameter methodParameter) {
|
||||
return new TypeDescriptor(nestedType, methodParameter);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -410,9 +410,9 @@ public class TypeDescriptor {
|
|||
|
||||
// subclassing hooks
|
||||
|
||||
protected TypeDescriptor(Class<?> nestedType, MethodParameter parentMethodParameter) {
|
||||
protected TypeDescriptor(Class<?> nestedType, MethodParameter methodParameter) {
|
||||
this.type = handleUnknownNestedType(nestedType);
|
||||
this.methodParameter = createNestedMethodParameter(parentMethodParameter);
|
||||
this.methodParameter = createNestedMethodParameter(methodParameter);
|
||||
}
|
||||
|
||||
protected Annotation[] resolveAnnotations() {
|
||||
|
|
|
|||
|
|
@ -54,12 +54,13 @@ public class PropertyTypeDescriptor extends TypeDescriptor {
|
|||
/**
|
||||
* Create a new type descriptor for a nested type declared on an array, collection, or map-based property.
|
||||
* Use this factory method when you've resolved a nested source object such as a collection element or map value and wish to have it converted.
|
||||
* Builds in protection for increasing the nesting level of the provided MethodParameter if the nestedType is itself a collection.
|
||||
* @param nestedType the nested type
|
||||
* @param parentMethodParameter the parent property's method parameter that declares the collection or map
|
||||
* @return the parent property descriptor
|
||||
* @param parentMethodParameter the method parameter
|
||||
* @return the property descriptor
|
||||
*/
|
||||
public static PropertyTypeDescriptor forNestedType(Class<?> nestedType, MethodParameter propertyMethodParameter, PropertyDescriptor propertyDescriptor) {
|
||||
return new PropertyTypeDescriptor(nestedType, propertyMethodParameter, propertyDescriptor);
|
||||
public static PropertyTypeDescriptor forNestedType(Class<?> nestedType, MethodParameter methodParameter, PropertyDescriptor propertyDescriptor) {
|
||||
return new PropertyTypeDescriptor(nestedType, methodParameter, propertyDescriptor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -120,4 +121,4 @@ public class PropertyTypeDescriptor extends TypeDescriptor {
|
|||
this.propertyDescriptor = propertyDescriptor;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue