NoSuchElementException: None.get in play framework for scala

0

I created the upadte method, but when I test it it shows the error NoSuchElementException: None.get

UserController

   object UserController extends Controller {

   def update(id:Long) = DBAction {  implicit rs =>

   var user = simpleUserForm.bindFromRequest.get

   user.id = Users.toOption(id)
   Users.update(user)
   Redirect(routes.UserController.list)
  }

   val simpleUserForm :Form[User] = Form {
    mapping(
     "firstName" -> nonEmptyText,
     "lastName" -> nonEmptyText,
     "email" -> email,
     "birthDate" -> nonEmptyText,
     "phone" -> nonEmptyText,
     "username" -> text,
     "password" -> nonEmptyText
   )(UserForm.fromSimpleForm)(UserForm.toSimpleForm)
  }

}

edit.scala.html

@import models.auth.Users
@(title: String, user:models.auth.User)

@main(title){

<form method="post" action="@controllers.auth.routes.UserController.update(Users.toLong(user.id))">
<input type="text" placeholder="First Name" name="firstName" value="@user.firstName"/><br/>
<input type="text" placeholder="Last Name" name="lastName" value="@user.lastName"/><br/>
<input type="email" placeholder="Email" name="email" value="@user.email" /><br/>
<input type="text" placeholder="Phone" name="phone" value="@user.phone" /><br/>
<input type="text" placeholder="Birthdate(dd/MM/yyyy)" name="birthDate" value="@user.birthDate" /><br/>
<input type="text" placeholder="Username" name="username" value="@user.username" /><br/>

<input type="submit" value="Update User" />

}

routes

 POST        /user/:id/         controllers.auth.UserController.update(id:Long)

I've done create, read and delete, but by update I found the error in that line

var user = simpleUserForm.bindFromRequest.get

the error is NoSuchElementException: None.get

    
asked by anonymous 30.01.2015 / 19:36

1 answer

1

You may have already solved this problem, I suppose, but it's clear that your bindFromRequest is empty, which causes None.

At the time of doing the .get you do not check if the bindFromRequest has value or not, which can result in None.get instead of Some.get

    
05.06.2015 / 15:44