array autogrow on set e.g. array[0]=foo
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3887 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
407c54ca29
commit
7d9e728c55
|
|
@ -37,7 +37,6 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.springframework.core.CollectionFactory;
|
import org.springframework.core.CollectionFactory;
|
||||||
import org.springframework.core.GenericCollectionTypeResolver;
|
import org.springframework.core.GenericCollectionTypeResolver;
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
|
|
@ -946,12 +945,18 @@ public class BeanWrapperImpl extends AbstractPropertyAccessor implements BeanWra
|
||||||
int arrayIndex = Integer.parseInt(key);
|
int arrayIndex = Integer.parseInt(key);
|
||||||
Object oldValue = null;
|
Object oldValue = null;
|
||||||
try {
|
try {
|
||||||
if (isExtractOldValueForEditor()) {
|
if (isExtractOldValueForEditor() && arrayIndex < Array.getLength(propValue)) {
|
||||||
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, tokens.keys.length), pd));
|
PropertyTypeDescriptor.forNestedType(requiredType, new MethodParameter(pd.getReadMethod(), -1, tokens.keys.length), pd));
|
||||||
|
// TODO reduce this grow algorithm along side the null gap algorithm for setting lists below ... the two are inconsistent
|
||||||
|
propValue = growArrayIfNecessary(propValue, arrayIndex, actualName);
|
||||||
Array.set(propValue, arrayIndex, convertedValue);
|
Array.set(propValue, arrayIndex, convertedValue);
|
||||||
|
PropertyValue newValue = new PropertyValue(actualName, propValue);
|
||||||
|
newValue.resolvedDescriptor = pd;
|
||||||
|
newValue.conversionNecessary = false;
|
||||||
|
setPropertyValue(newValue);
|
||||||
}
|
}
|
||||||
catch (IndexOutOfBoundsException ex) {
|
catch (IndexOutOfBoundsException ex) {
|
||||||
throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
|
throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ import java.util.Locale;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.MutablePropertyValues;
|
import org.springframework.beans.MutablePropertyValues;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
|
|
|
||||||
|
|
@ -94,14 +94,13 @@ public class Spr7839Tests {
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void arrayOfLists() throws Exception {
|
public void arrayOfLists() throws Exception {
|
||||||
// TODO two issues here: no autogrow for array properties, and GenericCollectionResolver not capable of accessing nested element type
|
// TODO TypeDescriptor not capable of accessing nested element type for arrays
|
||||||
request.setRequestURI("/nested/arrayOfLists");
|
request.setRequestURI("/nested/arrayOfLists");
|
||||||
request.addParameter("nested.arrayOfLists[0]", "Nested1,Nested2");
|
request.addParameter("nested.arrayOfLists[0]", "Nested1,Nested2");
|
||||||
adapter.handle(request, response, controller);
|
adapter.handle(request, response, controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void map() throws Exception {
|
public void map() throws Exception {
|
||||||
request.setRequestURI("/nested/map");
|
request.setRequestURI("/nested/map");
|
||||||
request.addParameter("nested.map['apple'].foo", "bar");
|
request.addParameter("nested.map['apple'].foo", "bar");
|
||||||
|
|
@ -145,7 +144,6 @@ public class Spr7839Tests {
|
||||||
|
|
||||||
@RequestMapping("/nested/arrayOfLists")
|
@RequestMapping("/nested/arrayOfLists")
|
||||||
public void handlerArrayOfLists(JavaBean bean) {
|
public void handlerArrayOfLists(JavaBean bean) {
|
||||||
System.out.println(bean.nested.arrayOfLists[0].get(1).getClass());
|
|
||||||
assertEquals("Nested2", bean.nested.arrayOfLists[0].get(1).foo);
|
assertEquals("Nested2", bean.nested.arrayOfLists[0].get(1).foo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue