Question

I'm trying to filter a collection in grails with findAll so I only get the instances with a certain value in his field "estado".
I have something like this:

trabajos.findAll({it.estado.equals( "Pago")})

The problem is I dont know how to paginate the returned collection.
I took a look at grails documentation and found this

Book.findAll(Map queryParams, Closure whereCriteria)

but when I try it

trabajos.findAll([offset: 0], {it.estado.equals("Pago")})

I get the following exception

No signature of method: java.util.ArrayList.findAll() is applicable for argument types:       (java.util.LinkedHashMap, com.publidirecta.PersonalController$_show_closure2) values: [[offset:0], com.publidirecta.PersonalController$_show_closure2@a6bdb0] 
Possible solutions: findAll(), findAll(), findAll(groovy.lang.Closure), findAll(groovy.lang.Closure), find(), find()`  

Is this a why to achieve some sort of pagination this why or would I have to do it manually?

No correct solution

OTHER TIPS

I guess you are muss 2 things: grails and groovy.
Book.findAll(Map queryParams, Closure whereCriteria) - is a finder in database, it's grails thing and you can pass max param in it.
But in trabajos.findAll({it.estado.equals( "Pago")}) you are trying to find in list. It's groovy thing. See more details here and here

If you try to get objects from database, use like this

Book.findAll(Map queryParams, Closure whereCriteria).

If it's a list of objects use something like this:

def filtered = trabajos.findAll({it.estado.equals( "Pago")})
def result = filteredList[offset..offset+max < filtered.size() ? offset+max : filtered.size()]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top