Grails 控制器/视图列表分页不显示下一个/上一个选项
我遇到了下一个/上一个选项未显示在 Groovy on Grails 站点的列表上的问题。我修改了自动生成的控制器代码,以将列表中的项目限制为用户创建的项目。这工作正常,但是,如果用户有超过 10 个项目,则下一个/上一个按钮不会按预期显示。以下是相关代码片段...
控制器:
def list = {
params.max = Math.min(params.max ? params.int('max') : 10, 100)
def login = authenticationService.getSessionUser().getLogin()
def authUser = AuthenticationUser.findByLogin(login)
def userAcct = User.findByLoginID(authUser)
def userServices = Service.createCriteria()
def results
if (userAcct.role == 'admin') {
results = userServices.list(params) {}
} else {
results = userServices.list(params) {
eq("userID", userAcct)
}
}
[serviceInstanceList: results, serviceInstanceTotal: results.count()]
}
GSP:
<div class="paginateButtons">
<g:paginate total="${serviceInstanceTotal}" />
</div>
当我使用具有“管理员”角色的帐户登录时,下一个/上一个链接显示正常。非管理员帐户在存在以下情况时不会显示下一个/上一个链接超过 10 项要列出。有人能看到我做错了什么吗?
I am having problems with the next/prev options not displaying on lists with a Groovy on Grails site. I have modified the automatically generated controller code to limit the items in the list to be items that were created by the user. This works fine, however, if the user has more than 10 items, the next/prev buttons don't show up as expected. Below are the relevant code snippits...
Controller:
def list = {
params.max = Math.min(params.max ? params.int('max') : 10, 100)
def login = authenticationService.getSessionUser().getLogin()
def authUser = AuthenticationUser.findByLogin(login)
def userAcct = User.findByLoginID(authUser)
def userServices = Service.createCriteria()
def results
if (userAcct.role == 'admin') {
results = userServices.list(params) {}
} else {
results = userServices.list(params) {
eq("userID", userAcct)
}
}
[serviceInstanceList: results, serviceInstanceTotal: results.count()]
}
GSP:
<div class="paginateButtons">
<g:paginate total="${serviceInstanceTotal}" />
</div>
When I log in with an account with the "admin' role, the next/prev links appear fine. Non-admin accounts do not display the next/prev links when there are more than 10 items to be listed. Can anyone see what I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的标准应该为您提供一个具有 TotalCount 的 pagedResultList。所以尝试一下
将控制器的最后一行更改为:
Your criteria should give you a pagedResultList which has a totalCount. So try
to change the last line of your controller to: