autoGrow support in DataBinder for field access
This commit harmonizes the autoGrow feature for both regular bean property and direct field access. Issue: SPR-8692
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -246,7 +246,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
|
||||
public void initDirectFieldAccess() {
|
||||
Assert.state(this.bindingResult == null,
|
||||
"DataBinder is already initialized - call initDirectFieldAccess before other configuration methods");
|
||||
this.bindingResult = new DirectFieldBindingResult(getTarget(), getObjectName());
|
||||
this.bindingResult = new DirectFieldBindingResult(getTarget(), getObjectName(), isAutoGrowNestedPaths());
|
||||
if (this.conversionService != null) {
|
||||
this.bindingResult.initConversion(this.conversionService);
|
||||
}
|
||||
|
||||
@@ -38,6 +38,8 @@ public class DirectFieldBindingResult extends AbstractPropertyBindingResult {
|
||||
|
||||
private final Object target;
|
||||
|
||||
private final boolean autoGrowNestedPaths;
|
||||
|
||||
private transient ConfigurablePropertyAccessor directFieldAccessor;
|
||||
|
||||
|
||||
@@ -47,8 +49,19 @@ public class DirectFieldBindingResult extends AbstractPropertyBindingResult {
|
||||
* @param objectName the name of the target object
|
||||
*/
|
||||
public DirectFieldBindingResult(Object target, String objectName) {
|
||||
this(target, objectName, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DirectFieldBindingResult instance.
|
||||
* @param target the target object to bind onto
|
||||
* @param objectName the name of the target object
|
||||
* @param autoGrowNestedPaths whether to "auto-grow" a nested path that contains a null value
|
||||
*/
|
||||
public DirectFieldBindingResult(Object target, String objectName, boolean autoGrowNestedPaths) {
|
||||
super(objectName);
|
||||
this.target = target;
|
||||
this.autoGrowNestedPaths = autoGrowNestedPaths;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +80,7 @@ public class DirectFieldBindingResult extends AbstractPropertyBindingResult {
|
||||
if (this.directFieldAccessor == null) {
|
||||
this.directFieldAccessor = createDirectFieldAccessor();
|
||||
this.directFieldAccessor.setExtractOldValueForEditor(true);
|
||||
this.directFieldAccessor.setAutoGrowNestedPaths(this.autoGrowNestedPaths);
|
||||
}
|
||||
return this.directFieldAccessor;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user