Nosuchelementexception: None.get em play framework para scala

Asked

Viewed 51 times

0

I created the upadte method, but when I test 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 already did create, read and delete, but by update I found the error on that line

var user = simpleUserForm.bindFromRequest.get

the error is Nosuchelementexception: None.get

1 answer

1


You must have already solved this problem, I believe, but anyway it is clear that your bindFromRequest is empty, which causes the None.

When it comes to doing . get you don’t check whether or not bindFromRequest has value, which you can do in None.get instead of Some.get

Browser other questions tagged

You are not signed in. Login or sign up in order to post.