Order not working with criteria in Grails
I just got started with groovy and grails and have some confusion regarding the criteria proposal.
Below is my code,
def order = "rollNumber"
def orderBy = "asc"
studentListCriteria = Students.createCriteria()
int max = 6
int offset = params?.offset ? Integer.valueOf(params.offset) : 0
def studentList = studentListCriteria.list(max: max, offset: offset) {
and {
eq("isActive", Boolean.TRUE )
}
order(order,orderBy)
}
While doing this, throw below errors.
groovy.lang.MissingMethodExceptionMessageNo signature of method: java.lang.String.call() is applicable for argument types: (java.lang.String, java.lang.String) values: [rollNumber, asc] Possible solutions: wait(), any(), tr(java.lang.String, java.lang.String), trim(), find(), size()
Can anyone suggest what I am doing wrong here?
+3
source to share
2 answers
Please check below code, you cannot use keywords here.
def orderParameter = "rollNumber"//Change name of variable.
def orderByParameter = "asc"
studentListCriteria = Students.createCriteria()
int max = 6
int offset = params?.offset ? Integer.valueOf(params.offset) : 0
def studentList = studentListCriteria.list(max: max, offset: offset) {
and {
eq("isActive", Boolean.TRUE )
}
order(orderParameter,orderByParameter)
}
Here you are using order
as a variable. Please change the name and go well.
+2
source to share