标签[paginate]缺少grails中必需的属性[total]

时间:2014-04-10 10:37:28

标签: grails-2.0

我有一个控制器资源 包tachemanagement

import org.springframework.dao.DataIntegrityViolationException

import tachemanagement.secu.Role

class RessourceeeController {

static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

def index() {
    redirect(action: "list", params: params)
}

def list(Integer max) {
    params.max = Math.min(max ?: 10, 100)
    [ressourceeeInstanceList: Ressourceee.list(params), ressourceeeInstanceTotal: Ressourceee.count()]
    [ roleInstanceList: Role.list( params ), roleInstanceTotal: Role.count() ]
}

def create() {
    [ressourceeeInstance: new Ressourceee(params)]
    [roleInstance: new Role(params)]



}


def save() {
    def ressourceeeInstance = new Ressourceee(params)
    def roleInstance = new Role(params)

    if (!ressourceeeInstance.save(flush: true)) {
        render(view: "create", model: [ressourceeeInstance: ressourceeeInstance])
        return
    }

    if (!roleInstance.save(flush: true)) {
        render(view: "create", model: [roleInstance: roleInstance])
        return
    }

    flash.message = message(code: 'default.created.message', args: [message(code: 'ressourceee.label', default: 'Ressourceee'), ressourceeeInstance.id])
    redirect(action: "show", id: ressourceeeInstance.id)
    flash.message = message(code: 'default.created.message', args: [message(code: 'role.label', default: 'Role'), roleInstance.id])
    redirect(action: "show", id: roleInstance.id)


}

def show(Long id) {
    def ressourceeeInstance = Ressourceee.get(id)
    def roleInstance = Role.get(id)
    if (!ressourceeeInstance) {
        flash.message = message(code: 'default.not.found.message', args: [message(code: 'ressourceee.label', default: 'Ressourceee'), id])
        redirect(action: "list")
        return
    }
    if(!roleInstance) {
        flash.message = message(code: 'default.not.found.message', args: [message(code: 'Role.label', default: 'Role'), id])
        redirect(action:list)
    }

    [ressourceeeInstance: ressourceeeInstance]
    [roleInstance: roleInstance]
}

def edit(Long id) {
    def ressourceeeInstance = Ressourceee.get(id)

    if (!ressourceeeInstance) {
        flash.message = message(code: 'default.not.found.message', args: [message(code: 'ressourceee.label', default: 'Ressourceee'), id])
        redirect(action: "list")
        return
    }

    [ressourceeeInstance: ressourceeeInstance]
}

def update(Long id, Long version) {
    def ressourceeeInstance = Ressourceee.get(id)

    if (!ressourceeeInstance) {
        flash.message = message(code: 'default.not.found.message', args: [message(code: 'ressourceee.label', default: 'Ressourceee'), id])
        redirect(action: "list")
        return
    }

    if (version != null) {
        if (ressourceeeInstance.version > version) {
            ressourceeeInstance.errors.rejectValue("version", "default.optimistic.locking.failure",
                      [message(code: 'ressourceee.label', default: 'Ressourceee')] as Object[],
                      "Another user has updated this Ressourceee while you were editing")
            render(view: "edit", model: [ressourceeeInstance: ressourceeeInstance])
            return
        }
    }

    ressourceeeInstance.properties = params

    if (!ressourceeeInstance.save(flush: true)) {
        render(view: "edit", model: [ressourceeeInstance: ressourceeeInstance])
        return
    }

    flash.message = message(code: 'default.updated.message', args: [message(code: 'ressourceee.label', default: 'Ressourceee'), ressourceeeInstance.id])
    redirect(action: "show", id: ressourceeeInstance.id)
}

def delete(Long id) {
    def ressourceeeInstance = Ressourceee.get(id)
    def roleInstance = Role.get(id)

    if (!ressourceeeInstance) {
        flash.message = message(code: 'default.not.found.message', args: [message(code: 'ressourceee.label', default: 'Ressourceee'), id])
        redirect(action: "list")
        return
    }
    if(!roleInstance) {


            flash.message = message(code: 'default.not.found.message', args: [message(code: 'role.label', default: 'Role'), id])
            redirect(action:list)
            return
        }

    try {
        ressourceeeInstance.delete(flush: true)
        flash.message = message(code: 'default.deleted.message', args: [message(code: 'ressourceee.label', default: 'Ressourceee'), id])
        redirect(action: "list")
    }
    catch (DataIntegrityViolationException e) {
        flash.message = message(code: 'default.not.deleted.message', args: [message(code: 'ressourceee.label', default: 'Ressourceee'), id])
        redirect(action: "show", id: id)
    }
    try {
        roleInstance.delete(flush: true)
        flash.message = message(code: 'default.deleted.message', args: [message(code: 'role.label', default: 'Role'), id])
        redirect(action: "list")
    }
    catch (DataIntegrityViolationException e) {
        flash.message = message(code: 'default.not.deleted.message', args: [message(code: 'role.label', default: 'Role'), id])
        redirect(action: "show", id: id)
    }
}

}  我已经为我的控制器添加了一个获取角色ID的代码 但它产生了一个问题 URI:/ tachemanagement / ressourceee / listClass:org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagExceptionMessage:Tag [paginate]缺少必需属性[total]

1 个答案:

答案 0 :(得分:0)

我想你忘了返回“total”变量。例如,在您的某个控制器中,您应该返回:

render(view: "create", model: [roleInstance: roleInstance, max: your_max_variable])

您的信息不清楚哪种操作会产生此类错误以及您如何输入g:pagination taglib