I'm trying to put into form ( select
) some values from database:
val kateg = Kategoria.findAll.map(a => (a.id.toString , a.nazwa))
And next in form:
bind("entry", xhtml,
"kateg" -> SHtml.select(kateg, Empty, select ),
"temat" -> SHtml.text(temat, temat = _),
"opis" -> SHtml.textarea(opis, opis = _, "cols" -> "80", "rows" -> "8"),
"submit" -> SHtml.submit("Add", processEntryAdd))
And then i have error:
Description Resource Path Location Type
type mismatch; found : List[(java.lang.String, a.nazwa.type) for
Some { val a: code.model.Kategoria }]
required: Seq[(String, String)] Forma.scala
/lift-todo-mongo/src/main/scala/code/snippet
line 51 Scala Problem
any ideas ? Thanks
SHtml.select(..)
allows you to choose a String
value.
It takes a Seq of tuples (Value: String
, Key: String
)
In that case you probably need to write:
val kateg = Kategoria.findAll.map(a => (a.id.toString , a.nazwa.is))
if nazwa is MappedString
field of Kategoria entity.
i.e. kateg should have a type of Seq[(String, String)]
But I would suggest you to use SHtml.selectObj
to select Kategoria entity instead of String name value:
val kateg: Seq[(Kategoria, String)] = Kategoria.findAll.map(a => (a, a.nazwa.is))
SHtml.selectObj[Kategoria](kateg, Empty, (k: Kategoria) => { .. /* assign */ .. })