Play 2.1.0 を使用しています。POST リクエストを受け入れ、リクエスト本文にブール値が必要なアクションを作成しようとしています。今起こっていることは、param を指定しなくても、Action が偽の値を取得することです。テストコード:
// /post/boolean/single routes to this method
def postTestBooleanSingle = Action { implicit request =>
val form = Form("flag" -> boolean)
form.bindFromRequest.fold(
formWithErrors =>
BadRequest(formWithErrors.errors map (fe => fe.key + ": " + fe.message) mkString ", "),
flag => Ok(f"got $flag%b")
)
}
// /post/num/single routes to this method
def postTestNumSingle = Action { implicit request =>
val form = Form("num" -> number)
form.bindFromRequest.fold(
formWithErrors =>
BadRequest(formWithErrors.errors map (fe => fe.key + ": " + fe.message) mkString ", "),
num => Ok(f"got $num%d")
)
}
$ curl -XPOST -d "num=42" http://localhost:9000/post/num/single
got 42
$ curl -XPOST http://localhost:9000/post/num/single
num: error.required // didn't provide num so i get an error
$ curl -XPOST -d "flag=true" http://localhost:9000/post/boolean/single
got true
$ curl -XPOST http://localhost:9000/post/boolean/single
got false // ???
ブール値パラメーターを要求するにはどうすればよいですか?