Reputation: 313
I'm new to grails.I'm using joda plugin for date and time.So i'm displaying date and time in separate column.Now i want to search date using criteria. I used below code in gsp page to search date.
<tr class="prop">
<td valign="top" class="name">
<label for="createdOn"><g:message code="asset.createdOn.label" default="Created On" /></label>
</td>
<td valign="top" class="value ${hasErrors(bean: assetInstance, field: 'createdOn', 'errors')}">
<joda:datePicker name="createdOn" precision="date" value="${assetInstance?.createdOn}" />
</td>
</tr>
i used below code in controller by using criteria.
def search= {
if (request.method == 'POST'){
def criteria = Asset.createCriteria()
def results = criteria {
or {
gt('createdOn','%' + params.createdOn + '%').toDate()
}
}
render(view:'list', model:[ assetInstanceList: results,assetInstanceTotal: Asset.count() ])
}
}
But it showing error.please guide me to solve this problem.
Upvotes: 0
Views: 325
Reputation: 120316
You probably want to bind your search to a command so that you have an actual bound Date object instead of a String parameter.
class SearchCommand {
LocalDate createdOn
...
}
You'll also need to fix your criteria.
def search = { SearchCommand command ->
...
def results = criteria {
or {
gt('createdOn', command.createdOn)
...
}
}
Upvotes: 1