Reputation: 33
I have just started working groovy and grails and has some confusion on Order clause with criteria.
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 executing it's throw below error.
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 am i doing wrong here??
Upvotes: 3
Views: 1158
Reputation: 954
Please check below Code, You can not 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 of it and good to go.
Upvotes: 3
Reputation: 7619
It's looks like you have a variable with name order
in your code before this criteria. Change it's name e.g.,
String orderBy = 'someThing'
....
def studentList = studentListCriteria.list(max: max, offset: offset) {
....
}
Upvotes: 1