I have problem with paginate, I use grails 2.4.4
This my index.gsp:
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<title></title>
</head>
<body>
<div>
<g:paginate controller="user" action="index" total="${userTotal}"/>
</div>
</body>
</html>
This is my controller:
class UserController {
def index() {
List<User> users = User.findAll()
render(view: "index", model: [users: users, userTotal: 4])
}
}
In the console I don't have any error and in my page I see nothing. Array users isn't empty, I checked.
It is my solution:
gsp:
<div class="content scaffold-list">
<g:form controller="user" action="index">
<label>Input user's name:</label>
<div class="form-group">
<g:textField name="userName"/>
<g:submitButton name="search"/>
</div>
<g:each var="user" in="${users}">
<p>User with name: ${user.name}</p>
</g:each>
</g:form>
<div class="pagination">
<g:paginate controller="user" action="index"
max="5" total="${userCount}"/>
</div>
</div>
controller:
def index(String userName) {
initUsersAndPokemons()
PagedResultList users = fourthService.findUsersByName(
userName,
params.int('max', 5),
params.int('offset', 0))
[users: users, userCount: users.getTotalCount()]
}
service:
PagedResultList findUsersByName(String userName, int max, int offset) {
BuildableCriteria bc = User.createCriteria()
bc.list(max: max, offset: offset) {
like('name',userName)
}
}