joergrech / KickstartWithBootstrap

Kickstart is an extension for Grails in order to start your project with a good looking frontend. It is intended to be used in rapid application scenarios such as a Startup Weekend or a prototyping session with a customer. This plugin provides adapted scaffolding templates for standard CRUD pages using Twitter's CSS Framework Bootstrap and offers some basic pages for a web site.
65 stars 52 forks source link

StructuredDateEditor accepts 5-digit years #31

Closed omixer closed 11 years ago

omixer commented 11 years ago

Hi Joerg,

This is more a request than a bug. The registered StructuredDateEditor accepts this date 01/02/20135 even if the specified default.date.format is dd/MM/yyyy. Validation goes well but when I save the instance holding this date I get the following exception:

MysqlDataTruncation: Data truncation: Incorrect datetime value: '20135-02-01 00:00:00'

I would either add this to the documentation so developers can decide how to handle it and avoid surprises or change the code to use StructuredDateEditor(DateFormat dateFormat, boolean allowEmpty, int exactDateLength) instead of StructuredDateEditor(DateFormat dateFormat, boolean allowEmpty) :

String dateFormat = messageSource.getMessage("default.date.format",null, 'dd/MM/yyyy', LocaleContextHolder.locale)
// do more logic here
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat)
simpleDateFormat.setLenient(false);
// Use StructuredDateEditor(DateFormat dateFormat, boolean allowEmpty, int exactDateLength)
// to give the exact date format length 
registry.registerCustomEditor(Date, new StructuredDateEditor(simpleDateFormat, true, dateFormat.length()))

For more on this issue check: https://jira.springsource.org/browse/SPR-1049

Note that I am using version 0.6.1b (though i don't think is makes a difference if I update to the latest version)

Thank you.

joergrech commented 11 years ago

Thanks for the tipp. I played around with your solution and it works but this approach would also make dates before the year 1000 invalid. Maybe the best solution would be to check the date on the page using javascript or in a Controller.

Based on your suggestion I made a new section "developer notes" in the description.