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);
|
oldValue = Array.get(propValue, arrayIndex);
|
||||||
}
|
}
|
||||||
Object convertedValue = convertIfNecessary(propertyName, oldValue, pv.getValue(), requiredType,
|
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);
|
Array.set(propValue, arrayIndex, convertedValue);
|
||||||
}
|
}
|
||||||
catch (IndexOutOfBoundsException ex) {
|
catch (IndexOutOfBoundsException ex) {
|
||||||
|
|
@ -953,9 +953,8 @@ public class BeanWrapperImpl extends AbstractPropertyAccessor implements BeanWra
|
||||||
if (isExtractOldValueForEditor() && index < list.size()) {
|
if (isExtractOldValueForEditor() && index < list.size()) {
|
||||||
oldValue = list.get(index);
|
oldValue = list.get(index);
|
||||||
}
|
}
|
||||||
// TODO method parameter nesting level should be token.keys.length + 1
|
|
||||||
Object convertedValue = convertIfNecessary(propertyName, oldValue, pv.getValue(), requiredType,
|
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()) {
|
if (index < list.size()) {
|
||||||
list.set(index, convertedValue);
|
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
|
// TODO method parameter nesting level should be token.keys.length + 1
|
||||||
Object convertedMapValue = convertIfNecessary(
|
Object convertedMapValue = convertIfNecessary(
|
||||||
propertyName, oldValue, pv.getValue(), mapValueType,
|
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);
|
map.put(convertedMapKey, convertedMapValue);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,18 @@ public class NumberFormattingTests {
|
||||||
assertEquals("2,35.00", binder.getBindingResult().getFieldValue("patternList[1]"));
|
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")
|
@SuppressWarnings("unused")
|
||||||
private static class TestBean {
|
private static class TestBean {
|
||||||
|
|
@ -175,7 +187,10 @@ public class NumberFormattingTests {
|
||||||
private BigDecimal[] patternArray;
|
private BigDecimal[] patternArray;
|
||||||
|
|
||||||
@NumberFormat(pattern="#,##.00")
|
@NumberFormat(pattern="#,##.00")
|
||||||
private List[] patternList;
|
private List<BigDecimal>[] patternList;
|
||||||
|
|
||||||
|
@NumberFormat(pattern="#,##.00")
|
||||||
|
private List<BigDecimal> patternList2;
|
||||||
|
|
||||||
public Integer getNumberDefault() {
|
public Integer getNumberDefault() {
|
||||||
return numberDefault;
|
return numberDefault;
|
||||||
|
|
@ -225,13 +240,22 @@ public class NumberFormattingTests {
|
||||||
this.patternArray = patternArray;
|
this.patternArray = patternArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List[] getPatternList() {
|
public List<BigDecimal>[] getPatternList() {
|
||||||
return patternList;
|
return patternList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPatternList(List[] patternList) {
|
public void setPatternList(List<BigDecimal>[] patternList) {
|
||||||
this.patternList = 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.
|
* 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.
|
* 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 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
|
* @return the nested type descriptor
|
||||||
*/
|
*/
|
||||||
public static TypeDescriptor forNestedType(Class<?> nestedType, MethodParameter parentMethodParameter) {
|
public static TypeDescriptor forNestedType(Class<?> nestedType, MethodParameter methodParameter) {
|
||||||
return new TypeDescriptor(nestedType, parentMethodParameter);
|
return new TypeDescriptor(nestedType, methodParameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -410,9 +410,9 @@ public class TypeDescriptor {
|
||||||
|
|
||||||
// subclassing hooks
|
// subclassing hooks
|
||||||
|
|
||||||
protected TypeDescriptor(Class<?> nestedType, MethodParameter parentMethodParameter) {
|
protected TypeDescriptor(Class<?> nestedType, MethodParameter methodParameter) {
|
||||||
this.type = handleUnknownNestedType(nestedType);
|
this.type = handleUnknownNestedType(nestedType);
|
||||||
this.methodParameter = createNestedMethodParameter(parentMethodParameter);
|
this.methodParameter = createNestedMethodParameter(methodParameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Annotation[] resolveAnnotations() {
|
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.
|
* 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.
|
* 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 nestedType the nested type
|
||||||
* @param parentMethodParameter the parent property's method parameter that declares the collection or map
|
* @param parentMethodParameter the method parameter
|
||||||
* @return the parent property descriptor
|
* @return the property descriptor
|
||||||
*/
|
*/
|
||||||
public static PropertyTypeDescriptor forNestedType(Class<?> nestedType, MethodParameter propertyMethodParameter, PropertyDescriptor propertyDescriptor) {
|
public static PropertyTypeDescriptor forNestedType(Class<?> nestedType, MethodParameter methodParameter, PropertyDescriptor propertyDescriptor) {
|
||||||
return new PropertyTypeDescriptor(nestedType, propertyMethodParameter, propertyDescriptor);
|
return new PropertyTypeDescriptor(nestedType, methodParameter, propertyDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue