nested properties polish
This commit is contained in:
parent
dc5faec189
commit
ec2833cd63
|
|
@ -133,7 +133,7 @@ public class GenericBinder implements Binder {
|
|||
} else if (binding.isList()) {
|
||||
binding = binding.getListElementBinding(element.getIntValue());
|
||||
} else {
|
||||
throw new IllegalArgumentException("Attempted to index a property that is not a Collection or Map");
|
||||
throw new IllegalArgumentException("Attempted to index a property that is not a List or Map");
|
||||
}
|
||||
} else {
|
||||
binding = binding.getBinding(element.getValue());
|
||||
|
|
@ -290,7 +290,7 @@ public class GenericBinder implements Binder {
|
|||
}
|
||||
|
||||
public Binding getBinding(String property, Object model) {
|
||||
return getBindingRule(property).getBinding(model);
|
||||
return getBindingRule(property, model.getClass()).getBinding(model);
|
||||
}
|
||||
|
||||
// implementing BindingRuleConfiguration
|
||||
|
|
@ -342,9 +342,13 @@ public class GenericBinder implements Binder {
|
|||
}
|
||||
|
||||
GenericBindingRule getBindingRule(String property) {
|
||||
return getBindingRule(property, this.property.getPropertyType());
|
||||
}
|
||||
|
||||
GenericBindingRule getBindingRule(String property, Class modelClass) {
|
||||
GenericBindingRule rule = nestedBindingRules.get(property);
|
||||
if (rule == null) {
|
||||
rule = new GenericBindingRule(property, this.property.getPropertyType());
|
||||
rule = new GenericBindingRule(property, modelClass);
|
||||
nestedBindingRules.put(property, rule);
|
||||
}
|
||||
return rule;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import org.junit.Before;
|
|||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.core.style.ToStringCreator;
|
||||
import org.springframework.ui.binding.Binding;
|
||||
import org.springframework.ui.binding.BindingResults;
|
||||
import org.springframework.ui.binding.MissingSourceValuesException;
|
||||
|
|
@ -365,13 +366,14 @@ public class GenericBinderTests {
|
|||
values.put("addresses[1].zip", "32901");
|
||||
|
||||
// Auto adds new Address at 5 (plus intermediates 2,3,4)
|
||||
values.put("addresses[5].street", "1234 Rostock Circle");
|
||||
values.put("addresses[5].street", "7891 Rostock Circle");
|
||||
values.put("addresses[5].city", "Palm Bay");
|
||||
values.put("addresses[5].state", "FL");
|
||||
values.put("addresses[5].zip", "32901");
|
||||
|
||||
BindingResults results = binder.bind(values);
|
||||
System.out.println(results);
|
||||
System.out.println(bean);
|
||||
Assert.assertEquals(6, bean.addresses.size());
|
||||
Assert.assertEquals("Palm Bay", bean.addresses.get(1).city);
|
||||
Assert.assertNotNull(bean.addresses.get(2));
|
||||
|
|
@ -537,6 +539,9 @@ public class GenericBinderTests {
|
|||
this.primaryAddress = primaryAddress;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return new ToStringCreator(this).append("addressses", addresses).toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static class AddressFormatter implements Formatter<Address> {
|
||||
|
|
@ -627,6 +632,9 @@ public class GenericBinderTests {
|
|||
this.country = country;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return new ToStringCreator(this).append("street", street).append("city", city).append("state", state).append("zip", zip).toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static class CurrencyAnnotationFormatterFactory implements
|
||||
|
|
|
|||
Loading…
Reference in New Issue