A
A
Anatoly Evladov2016-06-11 11:56:11
Scala
Anatoly Evladov, 2016-06-11 11:56:11

Play Framework comes form, how to process it correctly?

I receive a form like this:
Form([email protected],Map(action -> user_auth, args[accountName] -> Login, args[code] -> code123, secret_key -> secret_key111)..
I need to correctly extract the values ​​of args.accountName and args.code
I created the following case classes:

case class Args(accountName: String, code: String)
case class MyClass(action: String, args: Args, secret_key: String)

I process like this:
object MyClassForm {
  val form = Form(mapping(
    "action" -> nonEmptyText,
    "args" -> mapping(
      "accountName" -> nonEmptyText,
      "code" -> nonEmptyText
    )(Args.apply)(Args.unapply),
    "secret_key" -> nonEmptyText
  )(MyClass.apply)(MyClass.unapply)
  )
}

But apparently I did something wrong, because. when I receive a request, I see:
error: Form([email protected],Map(action -> user_auth, args[accountName] -> Login, args[code] -> 32112ds, secret_key -> 312),List( FormError(args.accountName,List(error.required),List()), FormError(args.code,List(error.required),List())),None)
What did I do wrong? And how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem, 2016-06-11
@mrRontgen

According to the Play Framework documentation,

Note: When you are using nested data this way, the form values ​​sent by the browser must be named like address.street, address.city, etc.
( link )
You're trying to parse a form like
this. I guess that's the problem. It seems to me that the simplest solution in this case would be to preprocess the request and change the variable names in it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question