Manu Chadha
Manu Chadha

Reputation: 16735

IntelliJ cannot resolve mapping function - PlayFramework

I am experimenting with Forms in Play 2.x on IntelliJ IDE

I have a case class in Models package

package Models
case class User (name:String){}

In controller, I have some hard-coded values which I want to send back in html

object Data extends Controller {
  //hard coded data
  val userData:Map[String,String] = Map("name"->"Eminem")

  **/*Error:(23, 34) not found: value mapping */

  val userForm:Form[User] = Form(mapping("name" -> text)(User.apply)(User.unapply) )

  //map hard coded data to Form and the create User instance
  User u = userForm.bind(userData).get()

  def test = Action {

    Ok(views.html.index("Your new application is ready.")(u))
  }
}

What mistake am I making? Why does not the code compile?

Upvotes: 0

Views: 222

Answers (1)

Manu Chadha
Manu Chadha

Reputation: 16735

The mistake was I didn't import Forms. Forms is separate from Form:

import play.api.data.Forms.{mapping,text}

Upvotes: 1

Related Questions