diff --git a/spring-context/src/main/java/org/springframework/validation/DirectFieldBindingResult.java b/spring-context/src/main/java/org/springframework/validation/DirectFieldBindingResult.java index a168cd141e..caa986d446 100644 --- a/spring-context/src/main/java/org/springframework/validation/DirectFieldBindingResult.java +++ b/spring-context/src/main/java/org/springframework/validation/DirectFieldBindingResult.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 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. @@ -25,8 +25,7 @@ import org.springframework.util.Assert; * supporting registration and evaluation of binding errors on value objects. * Performs direct field access instead of going through JavaBean getters. * - *
This implementation just supports fields in the actual target object. - * It is not able to traverse nested fields. + *
Since Spring 4.1 this implementation is able to traverse nested fields. * * @author Juergen Hoeller * @since 2.0 diff --git a/spring-context/src/test/java/org/springframework/tests/sample/beans/FieldAccessBean.java b/spring-context/src/test/java/org/springframework/tests/sample/beans/FieldAccessBean.java index a250f329cb..b387eaf395 100644 --- a/spring-context/src/test/java/org/springframework/tests/sample/beans/FieldAccessBean.java +++ b/spring-context/src/test/java/org/springframework/tests/sample/beans/FieldAccessBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006 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. @@ -28,6 +28,9 @@ public class FieldAccessBean { private TestBean spouse; + public FieldAccessBean() { + this.spouse = new TestBean(); + } public String getName() { return name; diff --git a/spring-context/src/test/java/org/springframework/validation/DataBinderFieldAccessTests.java b/spring-context/src/test/java/org/springframework/validation/DataBinderFieldAccessTests.java index bf2031ba53..f04b5d2731 100644 --- a/spring-context/src/test/java/org/springframework/validation/DataBinderFieldAccessTests.java +++ b/spring-context/src/test/java/org/springframework/validation/DataBinderFieldAccessTests.java @@ -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. @@ -29,6 +29,7 @@ import org.springframework.tests.sample.beans.TestBean; /** * @author Juergen Hoeller + * @author Stephane Nicoll * @since 07.03.2006 */ public class DataBinderFieldAccessTests extends TestCase { @@ -109,6 +110,22 @@ public class DataBinderFieldAccessTests extends TestCase { } } + public void testedNestedBindingWithDefaultConversionNoErrors() throws Exception { + FieldAccessBean rod = new FieldAccessBean(); + DataBinder binder = new DataBinder(rod, "person"); + assertTrue(binder.isIgnoreUnknownFields()); + binder.initDirectFieldAccess(); + MutablePropertyValues pvs = new MutablePropertyValues(); + pvs.addPropertyValue(new PropertyValue("spouse.name", "Kerry")); + pvs.addPropertyValue(new PropertyValue("spouse.jedi", "on")); + + binder.bind(pvs); + binder.close(); + + assertEquals("Kerry", rod.getSpouse().getName()); + assertTrue((rod.getSpouse()).isJedi()); + } + public void testBindingWithErrorsAndCustomEditors() throws Exception { FieldAccessBean rod = new FieldAccessBean(); DataBinder binder = new DataBinder(rod, "person");