Hi, there's a simple form in Lift framework and a Class with render method that handles the form:
def render(xhtml:NodeSeq) = {
var name = ""
var role = ""
var human = ""
def register = {
val person = new Person
person.name = name
person.role = role
person.human = if (human == "yes") "true" else "false"
model.create(person)
S.redirectTo("/index")
}
bind("user",
xhtml,
("name" -> SHtml.text(name, name = _)),
("role" -> SHtml.text(role, role = _)),
("human" -> SHtml.text(human,human = _)),
("submit" -> SHtml.submit("Register",register)))
}
When I run this example, eg. I access the url which is binded to the according form, I get following error:
Message: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number
...
...
...
epsilon.sjbs.CrudModel$class.create(Sjbs.scala:14)
epsilon.sjbs.PersonModel.create(Sjbs.scala:7)
epsilon.snippet.PersonSnippet.register$1(Snippet.scala:33)
epsilon.snippet.PersonSnippet.render(Snippet.scala:41)
this looks like that the register method is ran even there's no click on submit, just accessing the url. Why?
EDIT:this is my original entity
@NamedQuery(name = "findAll", query = "select x from Person x")
@Entity class Person extends Id with Name{
@OneToMany(mappedBy="person", cascade=Array(CascadeType.REMOVE))
var participated:java.util.List[Participant] = new java.util.ArrayListParticipant
var role:String = Role.User
var human:String = _
}