Grails paginate问题

时间:2012-03-09 20:58:04

标签: java grails

I have a simple paginate issue and get the following error... 
Hoping for some advice. I am relearning grails using version 2.1 and when I attempt to make a page with the paginate section is it failing.


Error 500: Internal Server Error
URI
/tictoc/
Class
groovy.lang.MissingMethodException
Message
No signature of method: tictoc.Event.withCritera() is applicable for argument types: (tictoc.StoreController$_closure2_closure3) values: [tictoc.StoreController$_closure2_closure3@10cea05] Possible solutions: withCriteria(groovy.lang.Closure), withCriteria(java.util.Map, groovy.lang.Closure)
Around line 27 of grails-app\controllers\tictoc\StoreController.groovy
24:        
25:        def total = Event.countByActive(true)
26:        
27:        def eventList = Event.withCritera {
28:        
29:            eq 'active', params.active
30:            projections {
Around line 13 of grails-app\controllers\tictoc\StoreController.groovy
10:    def show = {
11:    
12:        log.error 'exec activeEvents'
13:        activeEvents()
14:
15:    }
16:

//这是域类,我正在使用活动字段进行withCritera搜索。我希望它是一个布尔值,但我不确定它是否正常工作。

package tictoc

import java.math.BigInteger

class Event implements Cloneable {

    Integer id
    String name
    Date startDate
    Date endDate
    String desc
    String active 

    static constraints = {
        name(nullable:true)
        startDate(nullable:true)
        endDate(nullable:true)
        desc(nullable:true)
        active(nullable:true)
    }

    public String toString(){
        return "id:" + this.id + 
               " name:" + this.name + 
               " startDate:" + this.startDate +
               " endDate:" + this.endDate;
    }

    public int hashCode() {
        int hash = 1
        hash = hash * 31 + id.hashCode()
        hash = hash * 31 + name.hashCode()
        hash = hash * 31 + this.startDate
        hash = hash * 31 + this.endDate
        return hash
    }

    public boolean equals(Object anObject) {

        if (anObject != null &&
            anObject instanceof Event)
        {
            Ticket aThing = (Ticket)anObject;
            return (this.id == aThing.id) && 
                   (this.name == aThing.name) && 
                   (this.startDate == aThing.startDate) && 
                   (this.endDate == aThing.endDate)
        }

        return false;
    }
}

//这是GSP,而paginate部分没有显示下一个/上一个按钮:

<%@ page import="tictoc.Store" %>
<!doctype html>
<html>
    <head>
        <meta name="layout" content="main">
        <g:set var="entityName" value="${message(code: 'store.label', default: 'Store')}" />
        <title><g:message code="default.show.label" args="[entityName]" /></title>
    </head>
    <body>

        <h1> Ticket Store </h1>

        <table border=0 class="eventsTable">
            <tr>
                <th>Event</th>
                <th>Start </th>
                <th>End </th>
                <th>Description</th>
            </tr>
            <g:each var="event" in="${events}">

            <tr>
                <td>${event.name}</td>
                <td><g:formatDate format="MM/dd/yyyy" date="${event.startDate}"/></td>
                <td><g:formatDate format="MM/dd/yyyy" date="${event.endDate}"/></td>
                <td>${event.desc}</td>
            </tr>

            </g:each>
        </table>

        <div class="paginateButtons">
            <g:paginate controller="store"
                action="activeEvents"
                params="[name:active]"
                total="${totalEvents}" />
        </div>
    </body>
</html>

Here is the controller and i set the default page to activeEvents :

package tictoc

import tictoc.Event 

class StoreController {

    Event event
    static defaultAction = "activeEvents"

    def activeEvents = {
        log.error 'exec activeEvents'
        def max    = Math.min(params.max?.toInteger() ?:10, 100)
        def offset = params.offset?.toInteger() ?: 0
        def total = Event.countByActive(true)
        def eventList = Event.withCritera {

            eq 'active', params.active
            projections {
                event {

                    order 'name'
                }
            }
            maxResults max
            firstResult offset
        }

        return [events:eventList, 
                       totalEvents:total,
                       active:params.active]
    }
}

1 个答案:

答案 0 :(得分:3)

你拼错了withCriteria