Co-incidentally I was looking at the same problem today, and followed this answer from @Don. I was able to bind a date properly to the command object.
@Validateable
class BookCommand {
String name
Date pubDate
Integer pages
}
//Controller
def index(BookCommand cmd) {
println cmd.name
println cmd.pages
println cmd.pubDate
render "Done"
}
//src/groovy
class CustomDateEditorRegistrar implements PropertyEditorRegistrar {
public void registerCustomEditors(PropertyEditorRegistry registry) {
String dateFormat = 'yyyy/MM/dd'
registry.registerCustomEditor(Date, new CustomDateEditor(new SimpleDateFormat(dateFormat), true))
}
}
//URL
http://localhost:8080/poc_commandObject/book?name=Test&pages=10&pubDate=2012/11/11
//Println
Test
10
Sun Nov 11 00:00:00 EST 2012