Example usage for org.springframework.format.datetime.joda JodaDateTimeFormatAnnotationFormatterFactory getPrinter

List of usage examples for org.springframework.format.datetime.joda JodaDateTimeFormatAnnotationFormatterFactory getPrinter

Introduction

In this page you can find the example usage for org.springframework.format.datetime.joda JodaDateTimeFormatAnnotationFormatterFactory getPrinter.

Prototype

@Override
    public Printer<?> getPrinter(DateTimeFormat annotation, Class<?> fieldType) 

Source Link

Usage

From source file:org.wallride.web.support.ControllerUtils.java

private static String convertPropertyValueForString(Object target, PropertyDescriptor descriptor,
        Object propertyValue) {//from   ww w.  j  a v a  2s . co  m
    DateTimeFormat dateTimeFormat;
    try {
        dateTimeFormat = target.getClass().getDeclaredField(descriptor.getName())
                .getAnnotation(DateTimeFormat.class);
    } catch (NoSuchFieldException e) {
        throw new RuntimeException(e);
    }
    if (dateTimeFormat != null) {
        JodaDateTimeFormatAnnotationFormatterFactory factory = new JodaDateTimeFormatAnnotationFormatterFactory();
        Printer printer = factory.getPrinter(dateTimeFormat, descriptor.getPropertyType());
        return printer.print(propertyValue, LocaleContextHolder.getLocale());
    }
    return propertyValue.toString();
}