2012-03-09 14 views
0
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: [[email protected]] 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検索にはアクティブなフィールドを使用しています。ブール値にしたいと思っていましたが、それが機能しているかどうかはわかりませんでした。ここでGrailsページネームの問題

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] 
    } 
} 

答えて

3

あなたは間違ってwithCriteriaを綴られてきました。

+0

あなたのエラーメッセージを読むことを学ぶことは、grailsで持っている大きなスキルです:彼らは通常、あなたを正しい方向に導きます! –

関連する問題