I just came across this problem using the datePicker tag in a gsp – it appeared that there was no way to stop the tag showing today’s date when no value was set on the bean.
My tag looked like this:
<g:datePicker name="myDate" value="${myBean.aDate}" precision="day" years="${[2009, 2010, 2011]}" noSelection="${['':'--']}"/>
Whenever myBean.aDate was null the tag still displayed today’s date and no matter how I read the datePicker docs there seemed to be no solution, that is until I happened upon a mailing list post which showed a “default” attribute:
<g:datePicker name="myDate" value="${myBean.aDate}" precision="day" years="${[2009, 2010, 2011]}" noSelection="${['':'--']}" default="none"/>
The addition of “default=none” stops the tag showing today’s date and instead reverts to the noSelection value as I had originally expected. I have no idea what other values this “default” attribute can take, or where the code that reads it is in the Grails source (a search for datePicker in the source yielded nothing useful) so I can’t say anything more about it!
As soon as the Grails JIRA is back up (under maintenance at the moment, apparently) I’ll raise a bug on the docs.
Hey! looked good but no worky-worky! I still get just the new Date(). WTF? Regards, :-David.
Hi David, are you using the latest version of Grails (1.3.4)? If so there’s a bug which I discovered only last week that causes a new Date object to appear in your controller’s params when there’s no value set in the browser.
My solution, which differs slightly from the one in the bug report, was:
if (params.<datefield_name>_day == ”
|| params.<datefield_name>_month == ”
|| params.<datefield_name>_year == ”) {
params.remove(‘<datefield_name>’)
}
Maybe that will work for you, too?
Dave
fantastic – I was close to giving up and this is exactly what I was looking for. (I’m using Grails 2.0.0.RC2 , joda-time 1.3 plugin).
Thank you so much 🙂
thanks, helpful – docs need to be updated to include this