Grails datePicker magic

Been working much more on the frontend side of web development lately, but found a nice trick in Grails that seemed good to throw out there.

Maybe this is documented somewhere and I just always missed it. I knew the datePicker tag in gsp’s worked nicely for binding to domainClass objects through dataBinding, but didn’t know it could also be used as a super convenient way to get a date object in a controller. This is in grails 2.3 line BTW.


My use case was a simple report that needed to be run for a given month.

in the gsp:


Sweet. That is a really quick way to generate the HTML I want.

Now, here is the really slick part I didn’t know about. In the controller I can access the object and it will be a Date!

def report() {
	def forwardMonth =
	forwardMonth.roll(Calendar.MONTH, 1)
	forwardMonth  = forwardMonth.getTime()
	flash.message = "${} -- ${forwardMonth.toString()}"

Flattr this!