list binding working

This commit is contained in:
Keith Donald 2009-07-21 22:54:52 +00:00
parent 14dd30c5a5
commit 4e50c51139
3 changed files with 9 additions and 4 deletions

View File

@ -126,7 +126,6 @@ public class GenericBinder implements Binder {
public Binding getBinding(String property) { public Binding getBinding(String property) {
PropertyPath path = new PropertyPath(property); PropertyPath path = new PropertyPath(property);
Binding binding = getBindingRule(path.getFirstElement().getValue()).getBinding(model); Binding binding = getBindingRule(path.getFirstElement().getValue()).getBinding(model);
System.out.println(path);
for (PropertyPathElement element : path.getNestedElements()) { for (PropertyPathElement element : path.getNestedElements()) {
if (element.isIndex()) { if (element.isIndex()) {
if (binding.isMap()) { if (binding.isMap()) {
@ -303,6 +302,7 @@ public class GenericBinder implements Binder {
growListIfNecessary(index); growListIfNecessary(index);
Binding binding = listElementBindings.get(index); Binding binding = listElementBindings.get(index);
if (binding == null) { if (binding == null) {
final Map<String, Binding> nestedBindings = new HashMap<String, Binding>();
BindingContext listContext = new BindingContext() { BindingContext listContext = new BindingContext() {
public MessageSource getMessageSource() { public MessageSource getMessageSource() {
return GenericBindingRule.this.getMessageSource(); return GenericBindingRule.this.getMessageSource();
@ -313,8 +313,14 @@ public class GenericBinder implements Binder {
} }
public Binding getBinding(String property) { public Binding getBinding(String property) {
GenericBindingRule rule = GenericBindingRule.this.getBindingRule(property, getElementType());
Object model = ((List) GenericBindingRule.this.binding.getValue()).get(index); Object model = ((List) GenericBindingRule.this.binding.getValue()).get(index);
return GenericBindingRule.this.getBindingRule(property, getElementType()).getBinding(model); Binding binding = nestedBindings.get(property);
if (binding == null) {
binding = new PropertyBinding(rule.property, model, rule);
nestedBindings.put(property, binding);
}
return binding;
} }
public Formatter getFormatter() { public Formatter getFormatter() {

View File

@ -23,7 +23,7 @@ public class PropertyPath implements Iterable<PropertyPathElement> {
int start = prop.indexOf('['); int start = prop.indexOf('[');
int end = prop.indexOf(']', start); int end = prop.indexOf(']', start);
String index = prop.substring(start + 1, end); String index = prop.substring(start + 1, end);
elements.add(new PropertyPathElement(prop.substring(0, start), true)); elements.add(new PropertyPathElement(prop.substring(0, start), false));
elements.add(new PropertyPathElement(index, true)); elements.add(new PropertyPathElement(index, true));
} else { } else {
elements.add(new PropertyPathElement(prop, false)); elements.add(new PropertyPathElement(prop, false));

View File

@ -347,7 +347,6 @@ public class GenericBinderTests {
} }
@Test @Test
@Ignore
public void bindToListHandleNullValueInNestedPath() { public void bindToListHandleNullValueInNestedPath() {
Map<String, String> values = new LinkedHashMap<String, String>(); Map<String, String> values = new LinkedHashMap<String, String>();
// - new addresses List is created if null // - new addresses List is created if null