Pergunta

I'm trying to extract post params sent ajaxly ($.ajax(...)) with DynamicForm:

new DynamicForm().bindFromRequest()

And I get this error:

Caused by: java.lang.RuntimeException: There is no HTTP Context available from here.
    at play.mvc.Http$Context.current(Http.java:27) ~[play_2.9.1.jar:2.0.4]
    at play.mvc.Controller.request(Controller.java:28) ~[play_2.9.1.jar:2.0.4]
    at play.data.Form.requestData(Form.java:87) ~[play_2.9.1.jar:2.0.4]
    at play.data.DynamicForm.bindFromRequest(DynamicForm.java:46) ~[play_2.9.1.jar:2.0.4]
    at controllers.Login$$anonfun$login$1.apply(Login.scala:19) ~[classes/:2.0.4]
    at controllers.Login$$anonfun$login$1.apply(Login.scala:18) ~[classes/:2.0.4]

If I try to bind the params with a mapped normal form it works:

  val form = Form(
    tuple(
      "identity" -> nonEmptyText,
      "password" -> nonEmptyText,
      "loginType" -> nonEmptyText
    )
  )
  form.bindFromRequest

this is good for my login ajax post. But for other ajax posts I have I still would like to use DynamicForm and work with Map[String,String]. any idea what's the problem?

Foi útil?

Solução

My dev team and I had the same problem. In our case we used Java, the java.util collections package and the following line of code to bind request parameters to a Map.

final Map<String, String[]> myForm = request().body().asFormUrlEncoded();

I don't know Scala, but I think there's a way to use the Java collections in Scala.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top