删除操作无法呈现否则正常工作的模板

时间:2014-01-06 17:31:47

标签: grails

我正在开发Grails项目。我有一个模板,将显示一个人(也称为报告)的主管。从视图渲染时,此模板呈现正常,但是当执行删除操作时,我收到错误(下面的堆栈跟踪)。完全相同的查询在list()操作中运行正常,但在delete()操作失败。此外,我发现有趣的东西,当我“逐步”程序时,删除操作中的查询返回正确的结果。只有当我完成步骤时才会抛出错误。

SupervisorReportController.groovy

// Delete a specific SupervisorReport
def delete() {
    withSupervisorReport { supervisorReportInstance ->
        supervisorReportInstance.delete(flush: true)
        withFormat {
            html {
                def list = SupervisorReport.findAllByReport(Person.get(params.reportId as Integer))
                def message = 'Supervisor report deleted'
                def messageType = "Success"

                render(template:"/supervisorReport/displaySupervisorsTemplate", model: [supervisorReportInstanceList: list, message: message, messageType: messageType])
            }
        }
    }
}

列出行动

// Return a list of known SupervisorReports
def list() {
    // Limit the returned list to 100 at most, whatever the request has set, or 10 otherwise
    params.max = Math.min(params.max ? params.int('max') : 10, 100)

    // Return the list
    def list = SupervisorReport.findAllByReport(Person.get(params.id as Integer))
    def listObject = [supervisorReportInstanceList: list, id: params.id]
    withFormat {
        // The view needs more fluff, other responses just get the data
        html { listObject }
        json { render list as JSON }
        xml { render list as XML }
    }
}

template - _displaySupervisorsTemplate.gsp

<g:if test="${supervisorReportInstanceList.size() > 0}">
    <table class="table table-bordered table-hover table-striped table-dataTable">
        <caption class="hide">Supervisor Reports</caption>
        <thead>
        <tr>
            <th></th>
            <th>Name</th>
            <th>Employee Type</th>
            <th>Start Date</th>
            <th>Title</th>
        </tr>
        </thead>
        <tbody>
        <g:each var="supervisorReport" in="${supervisorReportInstanceList}">
            <tr>
                <td>
                    <g:form  action="delete" class="form-horizontal" method="post">
                        <g:hiddenField name="reportId" value="${supervisorReport.reportId}"/>
                        <g:hiddenField name="supervisorId" value="${supervisorReport.supervisorId}"/>
                        <g:actionSubmit class="delete"  value="${message(code: 'default.button.delete.label', default: 'delete')}" />
                    </g:form>
                </td>
                <td><pr:personLink person="${supervisorReport.supervisor}" /></td>
                <td>${fieldValue(bean: supervisorReport.supervisor, field: "employeeType")}</td>
                <td>${fieldValue(bean: supervisorReport.supervisor, field: "currentTitle.startDate")}</td>
                <td>${fieldValue(bean: supervisorReport.supervisor, field: "currentTitle.name")}</td>
            </tr>
        </g:each>
        </tbody>
    </table>
</g:if>
<g:else>
    <p>You have no Reports.</p>
</g:else>

栈跟踪

No signature of method: edu.wisc.radiology.performanceevaluations.SupervisorReport.findAllByReport() is applicable for argument types: () values: []
Possible solutions: findAllByReport([Ljava.lang.Object;). Stacktrace follows:
groovy.lang.MissingMethodException: No signature of method: edu.wisc.radiology.performanceevaluations.SupervisorReport.findAllByReport() is applicable for argument types: () values: []
Possible solutions: findAllByReport([Ljava.lang.Object;)
    at org.grails.datastore.gorm.GormStaticApi$_methodMissing_closure2.doCall(GormStaticApi.groovy:105)
    at edu.wisc.radiology.performanceevaluations.SupervisorReportController.list(SupervisorReportController.groovy:33)
    at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:195)
    at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
    at net.bull.javamelody.JspWrapper.invoke(JspWrapper.java:117)
    at net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler.invoke(JdbcWrapper.java:231)
    at edu.wisc.radiology.performanceevaluations.SupervisorReportController$_closure1_closure8_closure9.doCall(SupervisorReportController.groovy:177)
    at edu.wisc.radiology.performanceevaluations.SupervisorReportController$_closure1.doCall(SupervisorReportController.groovy:175)
    at edu.wisc.radiology.performanceevaluations.SupervisorReportController.delete(SupervisorReportController.groovy:151)
    at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:195)
    at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
    at net.bull.javamelody.JspWrapper.invoke(JspWrapper.java:117)
    at net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler.invoke(JdbcWrapper.java:231)
    at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:197)
    at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:171)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)

1 个答案:

答案 0 :(得分:1)

通过删除渲染函数的其他参数解决了这个问题。文档http://grails.org/doc/latest/ref/Controllers/render.html表示“警告 - 此方法并不总是支持多个参数。例如,如果同时指定集合和模型,则将忽略模型参数。参数”