开发者

grails paginated list not working correctly

Iam implementing the search functionality with pagination in my projext using grails. With the following code I can see the first resultSet with max=5, but when I click "next" it returns no data.

Below is code snippet: Controller code:

List <SearchCommand> empDetailsList = searchService.searchEmployee(searchCommand)

Service code:

def userlist = criteria.list(max:searchCommand.max, offset:searchCommand.offset){
        userProfiles {
            like ('firstName', "${searchCommand.firstName}%")   
            like ('lastName', "${searchCommand.lastName}%")
        }
        employees {
            like ('employeeNum', "${searchCommand.employeeNum}%")
            like ('payeNum', "${searchCommand.payeNum}%")
        }             
    }      
List <SearchCommand> searchCommandList = new ArrayList<SearchCommand>()   
for(userObject in userlist) {
    SearchCommand searchCommandObj = new SearchCommand()
    def user = userObject as SchemeUser
    UserProfile userp开发者_运维技巧rofile = UserProfile.findBySchemeUser(user)
    searchCommandObj.firstName =  userprofile.firstName
    searchCommandObj.lastName =  userprofile.lastName
    println "userprofile.firstName : " + userprofile.firstName
    Employee emp = Employee.findByUser(user)
    searchCommandObj.employeeNum =  emp.employeeNum
    searchCommandObj.payeNum =  emp.payeNum
    searchCommandList.add(searchCommandObj)
}
return searchCommandList

Iam using empDetailsList in gsp for pagination.

What do I need to fix so that the gsp correctly displays the result with pagination when click on 'Next'?


i think the total parameter for the paginate tag lib is missing. check if you using the right value for this tag attribute.

<g:paginate controller="ctrl" action="list" total="${totalValue}"/>

you can also control your max and offset values passed to the controller. furhtermore i can also control max and offset url parameters generated for the paginate links (1,2,...previous, next, ...).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜