Browse Source

array autogrow on set e.g. array[0]=foo

pull/7/head
Keith Donald 15 years ago
parent
commit
5d6840e877
  1. 9
      org.springframework.beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java
  2. 1
      org.springframework.context/src/test/java/org/springframework/format/number/NumberFormattingTests.java
  3. 4
      org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/Spr7839Tests.java

9
org.springframework.beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java

@ -37,7 +37,6 @@ import java.util.Set; @@ -37,7 +37,6 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.CollectionFactory;
import org.springframework.core.GenericCollectionTypeResolver;
import org.springframework.core.MethodParameter;
@ -946,12 +945,18 @@ public class BeanWrapperImpl extends AbstractPropertyAccessor implements BeanWra @@ -946,12 +945,18 @@ public class BeanWrapperImpl extends AbstractPropertyAccessor implements BeanWra
int arrayIndex = Integer.parseInt(key);
Object oldValue = null;
try {
if (isExtractOldValueForEditor()) {
if (isExtractOldValueForEditor() && arrayIndex < Array.getLength(propValue)) {
oldValue = Array.get(propValue, arrayIndex);
}
Object convertedValue = convertIfNecessary(propertyName, oldValue, pv.getValue(), requiredType,
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);
PropertyValue newValue = new PropertyValue(actualName, propValue);
newValue.resolvedDescriptor = pd;
newValue.conversionNecessary = false;
setPropertyValue(newValue);
}
catch (IndexOutOfBoundsException ex) {
throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,

1
org.springframework.context/src/test/java/org/springframework/format/number/NumberFormattingTests.java

@ -24,7 +24,6 @@ import java.util.Locale; @@ -24,7 +24,6 @@ import java.util.Locale;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.context.i18n.LocaleContextHolder;

4
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/Spr7839Tests.java

@ -94,14 +94,13 @@ public class Spr7839Tests { @@ -94,14 +94,13 @@ public class Spr7839Tests {
@Test
@Ignore
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.addParameter("nested.arrayOfLists[0]", "Nested1,Nested2");
adapter.handle(request, response, controller);
}
@Test
@Ignore
public void map() throws Exception {
request.setRequestURI("/nested/map");
request.addParameter("nested.map['apple'].foo", "bar");
@ -145,7 +144,6 @@ public class Spr7839Tests { @@ -145,7 +144,6 @@ public class Spr7839Tests {
@RequestMapping("/nested/arrayOfLists")
public void handlerArrayOfLists(JavaBean bean) {
System.out.println(bean.nested.arrayOfLists[0].get(1).getClass());
assertEquals("Nested2", bean.nested.arrayOfLists[0].get(1).foo);
}

Loading…
Cancel
Save