Browse Source

forgot to commit type descriptor

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@1492 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Keith Donald 17 years ago
parent
commit
9ee9fa1cae
  1. 16
      org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericBinder.java
  2. 15
      org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericFormatterRegistry.java
  3. 16
      org.springframework.context/src/test/java/org/springframework/ui/binding/support/GenericBinderTests.java
  4. 2
      org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java

16
org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericBinder.java

@ -576,6 +576,9 @@ public class GenericBinder implements Binder { @@ -576,6 +576,9 @@ public class GenericBinder implements Binder {
return results.size();
}
public String toString() {
return "[BindingResults = " + results.toString() + "]";
}
}
class InvalidFormat implements BindingResult {
@ -626,6 +629,11 @@ public class GenericBinder implements Binder { @@ -626,6 +629,11 @@ public class GenericBinder implements Binder {
}
};
}
public String toString() {
return getAlert().toString();
}
}
class Success implements BindingResult {
@ -672,6 +680,10 @@ public class GenericBinder implements Binder { @@ -672,6 +680,10 @@ public class GenericBinder implements Binder {
}
};
}
public String toString() {
return getAlert().toString();
}
}
@ -747,6 +759,10 @@ public class GenericBinder implements Binder { @@ -747,6 +759,10 @@ public class GenericBinder implements Binder {
};
}
public String toString() {
return getAlert().toString();
}
}
static abstract class AbstractAlert implements Alert {

15
org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericFormatterRegistry.java

@ -42,17 +42,18 @@ public class GenericFormatterRegistry implements FormatterRegistry { @@ -42,17 +42,18 @@ public class GenericFormatterRegistry implements FormatterRegistry {
private Map<Class, AnnotationFormatterFactory> annotationFormatters = new HashMap<Class, AnnotationFormatterFactory>();
public Formatter<?> getFormatter(TypeDescriptor<?> propertyType) {
Annotation[] annotations = propertyType.getAnnotations();
for (Annotation a : annotations) {
AnnotationFormatterFactory factory = annotationFormatters.get(a.annotationType());
if (factory != null) {
return factory.getFormatter(a);
}
}
Formatter<?> formatter = typeFormatters.get(propertyType.getType());
if (formatter != null) {
return formatter;
} else {
Annotation[] annotations = propertyType.getAnnotations();
for (Annotation a : annotations) {
AnnotationFormatterFactory factory = annotationFormatters.get(a.annotationType());
if (factory != null) {
return factory.getFormatter(a);
}
}
// TODO check class-level @Formatted annotation
return null;
}
}

16
org.springframework.context/src/test/java/org/springframework/ui/binding/support/GenericBinderTests.java

@ -17,6 +17,7 @@ import junit.framework.Assert; @@ -17,6 +17,7 @@ import junit.framework.Assert;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.ui.binding.Binding;
@ -223,6 +224,21 @@ public class GenericBinderTests { @@ -223,6 +224,21 @@ public class GenericBinderTests {
assertTrue(result.isFailure());
assertEquals("conversionFailed", result.getAlert().getCode());
}
@Test
@Ignore
public void bindToList() {
binder.addBinding("addresses");
Map<String, String> values = new LinkedHashMap<String, String>();
values.put("addresses[0]", "4655 Macy Lane, Melbourne FL 35452");
values.put("addresses[1]", "1234 Rostock Circle, Palm Bay FL 32901");
values.put("addresses[5]", "1977 Bel Aire Estates, Coker AL 12345");
BindingResults results = binder.bind(values);
assertEquals(3, results.size());
System.out.println(results);
Assert.assertEquals(6, bean.addresses.size());
Assert.assertEquals("Palm Bay", bean.addresses.get(1).city);
}
@Test
public void bindHandleNullValueInNestedPath() {

2
org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java

@ -191,7 +191,7 @@ public class TypeDescriptor<T> { @@ -191,7 +191,7 @@ public class TypeDescriptor<T> {
} else if (methodParameter != null) {
return methodParameter.getMethod().getAnnotations();
} else {
return null;
return new Annotation[0];
}
}

Loading…
Cancel
Save