Default date format in Spring WebFlow is "yyyy-MM-dd".
How to change to another format? "dd.mm.yyyy" for example.
Sorry for the late post but here is what you have to do. Spring Webflow does custom Data Binding. Its similar to how Spring MVC does it. The difference though is where it handles it. Spring MVC handles it on the controller level ( using the @InitBinder ).
Spring webflow does it on the binding level. Before executing a transition webflow will bind all parameter values to the object then validates the form (if validate="true") then invokes the transition on a successful validation.
What you need to do is to get webflow to change the means in which it binds a Date. You can do this by writing a custom converter.
First you will need a conversion service:
@Component("myConversionService")
public class MyConversionService extends DefaultConversionService {
public void MyConversionService() {
}
}
Webflow will use this service to determine what special binding needs to be accounted for. Now just write your specific date binder (keep in mind webflow defaults a date binder you will just override it).
@Component
public class MyDateToString extends StringToObject {
@Autowired
public MyDateToString(MyConversionService conversionService) {
super(Date.class);
conversionService.addConverter(this);
}
@Override
protected Object toObject(String string, Class targetClass) throws Exception {
try{
return new SimpleDateFormat("MM\dd\yyyy").parse(string);//whatever format you want
}catch(ParseException ex){
throw new ConversionExecutionException(string, String.class, targetClass, Date.class);//invokes the typeMissmatch
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With