Controller action does not compile with "detected type mismatch: Required device: play.api.mvc.Result"

I am new to Scala and Play. I need to create the CONTACTS module, but I get the following error:

type mismatch found : Unit required: play.api.mvc.Result 
    contactVal.save()
where contactVal is defined as 
    val contactVal  = new Contact(service) where service is 
    val service = new ExchangeService()

How to save a new EWS contact?

My code is:

def add = Action(parse.json) {
  implicit r=>
    val contactVal  = new Contact(service)
    val userId = (r.body \ "userId").asOpt[String].getOrElse("")
    val contactId = (r.body \ "id").asOpt[String].getOrElse("")
    val givenName = (r.body \ "givenName").asOpt[String].getOrElse("")
    val fName = (r.body \ "fName").asOpt[String].getOrElse("")
    val lName = (r.body \ "lName").asOpt[String].getOrElse("")
    val displayName = (r.body \ "displayName").asOpt[String].getOrElse("")
    val emailId1 = (r.body \ "emailId1").asOpt[String].getOrElse("")

    val streetB = (r.body \ "streetB").asOpt[String].getOrElse("")
    val cityB = (r.body \ "cityB").asOpt[String].getOrElse("")
    val stateB = (r.body \ "stateB").asOpt[String].getOrElse("")
    val postalcodeB = (r.body \ "postalcodeB").asOpt[String].getOrElse("")
    val countryB = (r.body \ "countryB").asOpt[String].getOrElse("")
    val phoneHome = (r.body \ "phoneHome").asOpt[Int].getOrElse("")
    val bday = (r.body \ "bday").asOpt[String].getOrElse("")

    contactVal.setGivenName(givenName)
    contactVal.setNickName(fName)
    contactVal.setSurname(lName)
    contactVal.setDisplayName(displayName)

    val bdayDate= new Date()
    bdayDate.setDate(bday.toInt)
    contactVal.setBirthday(bdayDate)

    contactVal.save()
}
+3
source share
1 answer

The problem is that the last line of code in your Action test does not return the play.api.mvc.Result object.

See: http://www.playframework.org/documentation/2.0.1/ScalaActions

Try adding Ok (or some other SimpleResult object) at the end of your action body. Example:

def add = Action(parse.json) { request =>
  ...
  contactVal.save()
  Ok("contact saved") // or if you want to render a templated: Ok(someTemplate())
}
+6
source

All Articles