0
votes

Image with error <--- when I use function update, I want to redirect to BooksController.index() but when i try it I have an error: object java.lang.ProcessBuilder.Redirect is not a value. Can somebody help?

BooksController:

val bookForm = Form(
    tuple(
      "id" -> number,
      "title" -> text,
      "price" -> number,
      "author" -> text
    )
  )


def edit(Id: Int) = Action {
    val book: Book = Book.findById(Id)
    Ok(views.html.edit())
  }


def update(Id: Int) = Action {
          implicit request =>
          val (id, title, price, author) = bookForm.bindFromRequest.get
          val book: Book = Book.findById(id)
          book.id = id
          book.title = title
          book.price = price
          book.author = author
          Redirect(routes.BooksController.index())
      }

My edit view:

<html>
<head>
    <title>Form example</title>
</head>
<body>
<form method="post" autocomplete="on">
    Id: <input type="text" name="id"><br><br>
    Title: <input type="text" name="title"><br><br>
    Price:<input type="text" name="price"><br><br>
    Author: <input type="text" name="author"><br><br>
    <input type="submit">
</form>
</body>
</html>

Routes:

GET     /books                      controllers.BooksController.index
GET     /books/create               controllers.BooksController.create
GET     /books/:id                  controllers.BooksController.show(id: Int)

POST    /books/create               controllers.BooksController.save

GET     /books/edit/:id             controllers.BooksController.edit(id: Int)
POST    /books/edit                 controllers.BooksController.update

Error: play.sbt.PlayExceptions$CompilationException: Compilation error[object java.lang.ProcessBuilder.Redirect is not a value] at play.sbt.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:34) at play.sbt.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:34) at scala.Option.map(Option.scala:146) at play.sbt.run.PlayReload$.$anonfun$taskFailureHandler$1(PlayReload.scala:33) at scala.Option.map(Option.scala:146) at play.sbt.run.PlayReload$.taskFailureHandler(PlayReload.scala:28) at play.sbt.run.PlayReload$.compileFailure(PlayReload.scala:24) at play.sbt.run.PlayReload$.$anonfun$compile$3(PlayReload.scala:51) at scala.util.Either$LeftProjection.map(Either.scala:573) at play.sbt.run.PlayReload$.compile(PlayReload.scala:51)

2
I answered your question, in the last question you posted. If that answer solves your problem delete this question, as it is a duplication of your last question.o-0
The answer didn't solves my problemMichael

2 Answers

0
votes

Lets look at the Redirect definition:

 /**
   * Generates a redirect simple result.
   *
   * @param url the URL to redirect to
   * @param status HTTP status
   */
  def Redirect(url: String, status: Int): Result = Redirect(url, Map.empty, status)

So your Redirect should be:

Redirect("/books")

Update

Ok, after you added the error, you error seems to be because of bookForm.bindFromRequest.get. So, if you look at the form in your html and your defined form:

id needs to be an input of type number and not text, as well as the price.

0
votes

Ok, so my friend resolve the problem. My mistake was in routes. I forgot to add id:

POST    /books/edit/:id            controllers.BooksController.update(id: Int)