Reputation: 8473
I'm getting some troubles with the tag and then updating my Date attribute from a model with the params sent.
Here is my tag:
<g:datePicker name="data" value="${controle.data}" precision="month"
years="${(Calendar.getInstance().get(Calendar.YEAR)-70)..Calendar.getInstance().get(Calendar.YEAR)}"/>
When I println the "params.data" it says "struct", but I can't simply do:
model.data = params.data
the params comes with params.data_month and params.data_year with the respectives values in String like:
[[data:struct], [data_month:1], [data_year:2009]]
I tried to do then:
model.data = new SimpleDateFormat("MM/yyyy").parse("${params.data_month}/${params.data_year}")
but it rejects the value, alerting: "Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'data'"
println model.data
println new SimpleDateFormat("MM/yyyy").parse("${params.data_month}/${params.data_year}")
--shows
2006-01-01 00:00:00.0
Sun Jan 01 00:00:00 BRST 2006
Upvotes: 0
Views: 1251
Reputation: 2193
but I can't simply do: model.data = params.data
Why not? Are you getting an exception, or are you just being mislead by outdated documentation? -
This is a feature since Grails 1.2. Conversion to a Date
type will be performed, automatically.
As for the SimpleDateFormat
issue, just add a day, like so:
model.data = new SimpleDateFormat("d/MM/yyyy").parse(
"1/${params.data_month}/${params.data_year}")
Upvotes: 1