I am trying to get every instance of a domain where there user is equal to current logged in user.
My code at the minute is:
def list(Integer max) {
params.max = Math.min(max ?: 10, 100)
if (lookupPerson().username == "admin"){
adminList(max)
}
else{
def childList = []
def i = 1
Child.list().each(){
if(Child.get(i).user.username == lookupPerson().username){
def child = Child.get(i)
childList.add(child)
}
i++
}
[childInstanceList: childList.list(params), childInstanceTotal: childList.count()]
}
}
This gives me the following error
No signature of method: java.util.ArrayList.list() is applicable for argument types: (org.codehaus.groovy.grails.web.servlet.mvc.GrailsParameterMap) values: [[action:list, controller:child, max:10]] Possible solutions: last(), first(), asList(), toList(), is(java.lang.Object), wait()
I’m sure there must be an easier and better way of doing this.
any ideas?
You can probably do what you’re after with a criteria query:
If your
paramshas pagination parameters then the “total” will be available aschildList.totalCount, you don’t need to calculate it separately.