Hi, I am wondering why there is a difference in query parameter handling when I am using Forms, and when I am using query parameters in the routes file.
Given this controller and routes file
GET /method controllers.ExperimentController.method(querySeq: List[String] ?= Nil)
class ExperimentController @Inject() (
) extends InjectedController {
def method(
querySeq: List[String]
) =
Action.async { implicit request =>
MyForm.form
.bindFromRequest()
.fold(
errors => println("Error " + errors),
form => println("OK" + form)
)
Future.successful(Ok(querySeq.toString()))
}
}
case class MyForm(formSeq: Seq[String])
object MyForm {
val form =
Form(mapping("formSeq" -> seq(text))(MyForm.apply)(MyForm.unapply))
}
Calling /method?querySeq=1&querySeq=2 results in that querySeq is List(1, 2) and form.querySeq is List()
Instead the form supports this syntax: /method?querySeq[]=a&querySeq[]=b, which results in querySeq is List() and form.querySeq is List(a, b).
Notice, that in order to test it the [ and ] must be URL encoded.
I wonder why is it like that?
Thanks,
René