@DateTimeFormat in form model still not working for me.
Am I doing something wrong?
Following working for me, But it's not that effective because I want to use dates in "yyyy-MM-dd HH:mm" and "yyyy-MM-dd" both. Now all my date inputs require "yyyy-MM-dd HH:mm".
Code:
package com.mobinet.wos.util.spring;
import java.util.Date;
import org.joda.time.DateTime;
import org.springframework.format.FormatterRegistry;
import org.springframework.format.datetime.DateFormatter;
import org.springframework.format.support.FormattingConversionServiceFactoryBean;
import org.springframework.stereotype.Component;
@Component("applicationConversionService")
public class ApplicationConversionServiceFactoryBean extends FormattingConversionServiceFactoryBean {
protected void installFormatters(FormatterRegistry registry) {
super.installFormatters(registry);
registry.addFormatterForFieldType(Date.class, new DateFormatter("yyyy-MM-dd HH:mm"));
}
}
BTW I'm using spring web flow 2.2.1, spring 3.0.5 and joda time 1.6.
Edit: I finally got it working @DateTimeFormat. Install JodaDateTimeFormatAnnotationFormatterFactory in conversion service.
Code:
package com.mobinet.wos.util.spring;
import org.springframework.format.FormatterRegistry;
import org.springframework.format.datetime.joda.JodaDateTimeFormatAnnotationFormatterFactory;
import org.springframework.format.support.FormattingConversionServiceFactoryBean;
import org.springframework.stereotype.Component;
@Component("applicationConversionService")
public class ApplicationConversionServiceFactoryBean extends FormattingConversionServiceFactoryBean {
protected void installFormatters(FormatterRegistry registry) {
super.installFormatters(registry);
registry.addFormatterForFieldAnnotation(new JodaDateTimeFormatAnnotationFormatterFactory());
}
}