Browse Source

fixed bug related to annotation driven formatting

pull/23217/head
Keith Donald 15 years ago
parent
commit
8a15486de3
  1. 11
      org.springframework.context/src/main/java/org/springframework/ui/format/jodatime/AbstractDateTimeAnnotationFormatterFactory.java
  2. 2
      org.springframework.context/src/main/java/org/springframework/ui/format/support/FormattingConversionService.java
  3. 2
      org.springframework.context/src/test/java/org/springframework/ui/format/jodatime/JodaTimeFormattingTests.java

11
org.springframework.context/src/main/java/org/springframework/ui/format/jodatime/AbstractDateTimeAnnotationFormatterFactory.java

@ -23,6 +23,9 @@ import java.util.HashSet; @@ -23,6 +23,9 @@ import java.util.HashSet;
import java.util.Set;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;
import org.joda.time.LocalTime;
import org.joda.time.ReadableInstant;
import org.joda.time.ReadablePartial;
import org.joda.time.format.DateTimeFormatter;
@ -52,7 +55,7 @@ abstract class AbstractDateTimeAnnotationFormatterFactory<A extends Annotation> @@ -52,7 +55,7 @@ abstract class AbstractDateTimeAnnotationFormatterFactory<A extends Annotation>
DateTimeFormatter formatter = configureDateTimeFormatterFrom(annotation);
if (ReadableInstant.class.isAssignableFrom(propertyType)) {
return new ReadableInstantPrinter(formatter);
} else if (ReadablePartial.class.equals(propertyType)) {
} else if (ReadablePartial.class.isAssignableFrom(propertyType)) {
return new ReadablePartialPrinter(formatter);
} else if (Calendar.class.isAssignableFrom(propertyType)) {
// assumes Calendar->ReadableInstant converter is registered
@ -78,8 +81,10 @@ abstract class AbstractDateTimeAnnotationFormatterFactory<A extends Annotation> @@ -78,8 +81,10 @@ abstract class AbstractDateTimeAnnotationFormatterFactory<A extends Annotation>
private Set<Class<?>> createFieldTypes() {
Set<Class<?>> propertyTypes = new HashSet<Class<?>>(5);
propertyTypes.add(ReadableInstant.class);
propertyTypes.add(ReadablePartial.class);
propertyTypes.add(LocalDate.class);
propertyTypes.add(LocalTime.class);
propertyTypes.add(LocalDateTime.class);
propertyTypes.add(DateTime.class);
propertyTypes.add(Date.class);
propertyTypes.add(Calendar.class);
propertyTypes.add(Long.class);

2
org.springframework.context/src/main/java/org/springframework/ui/format/support/FormattingConversionService.java

@ -88,7 +88,7 @@ public class FormattingConversionService implements FormatterRegistry, Conversio @@ -88,7 +88,7 @@ public class FormattingConversionService implements FormatterRegistry, Conversio
return sourceFieldType.getAnnotation(annotationType) != null;
}
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
Printer<?> printer = annotationFormatterFactory.getPrinter(sourceType.getAnnotation(annotationType), targetType.getType());
Printer<?> printer = annotationFormatterFactory.getPrinter(sourceType.getAnnotation(annotationType), sourceType.getType());
return new PrinterConverter(printer, conversionService).convert(source, sourceType, targetType);
}
public String toString() {

2
org.springframework.context/src/test/java/org/springframework/ui/format/jodatime/JodaTimeFormattingTests.java

@ -12,7 +12,6 @@ import org.joda.time.LocalDateTime; @@ -12,7 +12,6 @@ import org.joda.time.LocalDateTime;
import org.joda.time.LocalTime;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.context.i18n.LocaleContextHolder;
@ -60,7 +59,6 @@ public class JodaTimeFormattingTests { @@ -60,7 +59,6 @@ public class JodaTimeFormattingTests {
}
@Test
@Ignore
public void testBindLocalDateAnnotated() {
MutablePropertyValues propertyValues = new MutablePropertyValues();
propertyValues.addPropertyValue("localDateAnnotated", "Oct 31, 2009");

Loading…
Cancel
Save