Reputation: 451
When I attempt to use the grails datepicker, when I try out the page the value that gets sent to the controller is the default value, not the actual date value that I've chosen in the datepicker fields.
I'm using the grails datepicker in my simple index.gsp page:
<g:form action="show">
game ID: <g:textField name="gameId" value=""/><br/>
switch date: <g:datePicker name="switchDate" value="${new Date()}"/><br/>
<g:submitButton name="submit" value="submit"/>
</g:form>
my equally simple show controller:
def show(long gameId, Date switchDate) {
println("gameId:$gameId switchDate:$switchDate")
}
I'm guessing I'm missing something obvious. Thank you in advance.
Upvotes: 1
Views: 582
Reputation: 34011
I think this has to do with the Date
not being bound properly. If you access it through params.switchDate
or change the parameter to be of type String
:
def show(long gameId, String switchDate) {
then it works.
Alternatively you can follow the steps from this question to set up proper data binding for the Date, i.e. by setting:
grails.databinding.dateFormats = ['MMddyyyy HH:mm:ss']
in your Config.groovy
.
Upvotes: 1