0

我已经实现了一个基于 mongodb-record 的模型,我正在尝试编写表单以将数据(事件记录)存储到数据库中。

要存储的对象的片段是:

class eventSnippet extends StatefulSnippet with PaginatorSnippet[event] {

  var dispatch: DispatchIt = {
    case "editForm" => editForm _
  }

  var editingevent = event.createRecord


  def editForm(xhtml: NodeSeq): NodeSeq = {
        ("#editName" #> editingevent.title.toForm &
         "#editDescription" #> editingevent.description.toForm &
         "#editDT" #> editingevent.date_time.toForm &
         "#editCat" #> editingevent.category.toForm &
         "#editPrivacy" #> editingevent.privacy.toForm &
          "type=submit" #> SHtml.submit(?("Save"), () => save )).apply(xhtml)
  }

  def save = {
    editingevent.save
    redirectToHome
  }}

错误是:

class eventSnippet needs to be abstract, since:
[error] method page in trait Paginator of type => Seq[code.model.event] is not defined
[error] method count in trait Paginator of type => Long is not defined

当我将类更改为抽象时,它可以编译,但在浏览器上出现错误:

Message: java.lang.InstantiationException
sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:30)
java.lang.reflect.Constructor.newInstance(Constructor.java:513)

我正在使用 sbt 0.7.5 和 Scala 2.9.1。

4

1 回答 1

1

Lift 需要为您的代码段创建实例,因此它不能是抽象的。

我在您的代码段中看不到任何需要分页的内容。您应该简单地删除with PaginatorSnippet[event]而不是使类抽象。

如果确实需要分页,则必须提供pagecount方法的实现。

class eventSnippet extends StatefulSnippet with PaginatorSnippet[event] {
  def page: Seq[event] = // return itemsPerPage events, starting at curPage*itemsPerPage

  def count: Long = // return total count of events.

  // ...
}
于 2012-06-13T18:23:54.890 回答