我已经实现了一个基于mongodb记录的模型,我正在尝试编写表单来将数据(事件记录)存储到数据库中。
要存储的对象的片段是:
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
当我将类更改为abstract时,它会编译,但我在浏览器上出错:
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。
答案 0 :(得分:1)
Lift需要创建代码段的实例,因此它不能是抽象的。
我的代码段中没有任何内容需要分页。您只需删除with PaginatorSnippet[event]
,而不要使类抽象。
如果确实需要分页,则必须提供page
和count
方法的实现。
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.
// ...
}