Skip to content

Commit 22948bd

Browse files
committed
Add hook to create custom BeanPropertyBindingResult
Issue: SPR-13373
1 parent a3e7848 commit 22948bd

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

spring-context/src/main/java/org/springframework/validation/DataBinder.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
* @author Rod Johnson
9999
* @author Juergen Hoeller
100100
* @author Rob Harrop
101+
* @author Stephane Nicoll
101102
* @see #setAllowedFields
102103
* @see #setRequiredFields
103104
* @see #registerCustomEditor
@@ -250,29 +251,50 @@ public int getAutoGrowCollectionLimit() {
250251
* Initialize standard JavaBean property access for this DataBinder.
251252
* <p>This is the default; an explicit call just leads to eager initialization.
252253
* @see #initDirectFieldAccess()
254+
* @see #createBeanPropertyBindingResult()
253255
*/
254256
public void initBeanPropertyAccess() {
255257
Assert.state(this.bindingResult == null,
256258
"DataBinder is already initialized - call initBeanPropertyAccess before other configuration methods");
257-
this.bindingResult = new BeanPropertyBindingResult(
258-
getTarget(), getObjectName(), isAutoGrowNestedPaths(), getAutoGrowCollectionLimit());
259+
this.bindingResult = createBeanPropertyBindingResult();
260+
}
261+
262+
/**
263+
* Create the {@link AbstractPropertyBindingResult} instance using standard JavaBean
264+
* property access.
265+
*/
266+
protected AbstractPropertyBindingResult createBeanPropertyBindingResult() {
267+
BeanPropertyBindingResult result = new BeanPropertyBindingResult(getTarget(),
268+
getObjectName(), isAutoGrowNestedPaths(), getAutoGrowCollectionLimit());
259269
if (this.conversionService != null) {
260-
this.bindingResult.initConversion(this.conversionService);
270+
result.initConversion(this.conversionService);
261271
}
272+
return result;
262273
}
263274

264275
/**
265276
* Initialize direct field access for this DataBinder,
266277
* as alternative to the default bean property access.
267278
* @see #initBeanPropertyAccess()
279+
* @see #createDirectFieldBindingResult()
268280
*/
269281
public void initDirectFieldAccess() {
270282
Assert.state(this.bindingResult == null,
271283
"DataBinder is already initialized - call initDirectFieldAccess before other configuration methods");
272-
this.bindingResult = new DirectFieldBindingResult(getTarget(), getObjectName(), isAutoGrowNestedPaths());
284+
this.bindingResult = createDirectFieldBindingResult();
285+
}
286+
287+
/**
288+
* Create the {@link AbstractPropertyBindingResult} instance using direct field
289+
* access.
290+
*/
291+
protected AbstractPropertyBindingResult createDirectFieldBindingResult() {
292+
DirectFieldBindingResult result = new DirectFieldBindingResult(getTarget(),
293+
getObjectName(), isAutoGrowNestedPaths());
273294
if (this.conversionService != null) {
274-
this.bindingResult.initConversion(this.conversionService);
295+
result.initConversion(this.conversionService);
275296
}
297+
return result;
276298
}
277299

278300
/**

0 commit comments

Comments
 (0)