I have a country domain, and in the .gsp list I have a search box with an input field. The first problem was that when I tried to use paginate in my list, the whole result was always shown, in this case I set the solution, and I sent only 10 values โโto display (if you know another solution, tell me). My search is as follows:
def search = {
if(query){
def srchResults = searchableService.search(query, params)
def result = Country.executeQuery("select new map(a.name as name, a.datacenter as datacenter) from Country a where a.name like '%"+ params.q + "%'")
if (params.offset)
{
x = params.offset.toInteger()
y = Math.min(params.offset.toInteger()+9, result.size()-1)
} else
{
x = 0
size = result.size() - 1
y = Math.min(size, 9)
}
def q=params.q
[countryInstanceList: result.getAt(x .. y), countryInstanceTotal:result.size(), q:params.q]
}else{
redirect(action: "list")
}
}
Now I have another problem, when I click on the next page, then my parameters from the search field are cleared and the result is zero. I tried passing the value of the field as a parameter, but I'm doing something wrong.
My search page looks like this:
<g:form action="search">
<div class="search" >
Search Country
<g:hiddenField name="q" value="${params.q}" />
<input type="text" name="q" value="${params.q}" />
<input type="submit" value="Search"/>
</div>
</g:form>
...... ......