【发布时间】:2012-04-19 17:00:30
【问题描述】:
我想将 play 2.0 框架中的表单绑定与从circumflex-orm (website) 扩展 Record 的类结合起来。
这些是我的类对象:
class Task extends Record[Long, Task] with IdentityGenerator[Long, Task] {
def this(name: String, description: String) = {
this()
this.name := name
this.description := description
}
val id = "id".BIGINT.NOT_NULL.AUTO_INCREMENT
val name = "name".VARCHAR(255).NOT_NULL
val description = "description".TEXT.NOT_NULL
def PRIMARY_KEY = id
def relation = Task
}
这就是我尝试用播放形式做的事情:
val taskForm: Form[Tasks] = Form(
mapping(
"name" -> text,
"description" -> text
)
{(name, description) => Task(name, description)}
{(t: Task) => Option(t.name(), t.description()) }
)
但我收到这样的错误:
found : models.Task => Option[(String, String)]
required: Unit => Option[(String, String)]
{(t: Task) => Option(t.name(), t.description())}
如果我将 Option 替换为 Some:
found : models.Task => Some[(String, String)]
required: Unit => Option[(String, String)]
{(t: Task) => Some(t.name(), t.description())}
我现在一无所知,任何提示将不胜感激。
非常感谢。
编辑:我犯了一个基本错误,我确实命名了表单:
val taskForm: Form[Tasks] = Form(
当类的名称是“任务”时。所以我可以把它改成:
val taskForm: Form[Task] = Form(
mapping(
"name" -> text,
"description" -> text
) ( (name, description) => Task )
( (t: Task) => Option() )
)
现在我得到一个不同的错误:
Unspecified value parameter x
( (t: Task) => Option() )
我在eclipse中做了一个简单的项目,需要的依赖,你可以在这里下载看看,如果有帮助的话: Basic Form Example
【问题讨论】:
-
我认为
() => Some(t.name(), t.description())应该有帮助 -
然后它说:方法应用的参数太多:(x: A)Some[A] in object Some / {() => Some(t.name(), t.description() ) }
标签: forms scala orm playframework-2.0 circumflex-orm