当前位置: 动力学知识库 > 问答 > 编程问答 >

scala - Play form binding difficulties - How do I modify a request after getting it in the backend?

问题描述:

I'm currently trying to connect an Extjs form to a Play! Scala backend.

I have no problem receiving the request, but

FormName.bindFromRequest.get returns to me None .

I'm able to find the data generated via submitting from Extjs in the POST request in request.request.body.data (the first request object is generated by SocialSecure's controller), whereas normally the data bound to the form would be found in request.request.body.data.elems

I think Extjs's eschewal of using <form> in their inserted HTML is what causes me this problem, but I'd still like to take advantage of Extjs's nice form verification UI.

Does Play! or Scala have any resources for modifying a request after the server has received it?



More info

This is the method my /requestAudit cuurently points to after a POST request:

def requestAudit = SecuredAction(WithProvider("google")) { // SecureSocial syntax

implicit request => { // let's call this line 0'

println(request.request.body.asFormUrlEncoded) // let's call this line 1'

println(request.body.asText) // let's call this line 2'

newAuditForm.bindFromRequest.fold(

errors => BadRequest(views.html.error(newAuditForm))

success => { /*insert the object into my db*/ }

) } }


Ext.js request

When I'm debugging in Eclipse with an Ext.js form, the Variables window shows: (click for closeup)

where the form values are located in request.body.data.key1, request.body.data.key2, etc



Bootstrap form request

On the other hand, the request for Bootstrap has the values stored in request.body.data.elems

网友答案:

@2manyprojects 's suggestion set me on the right path:

newAuditForm.bindFromRequest(
  (request.request.body.asFormUrlEncoded).getOrElse(Map()))
      .fold( ... )

worked.

I was still getting form binding errors after changing my code to this, and then I discovered a typo in the name property of one of my Ext.js form fields. The name of the field must be the same on both the UI and the Play Form.

分享给朋友:
您可能感兴趣的文章:
随机阅读: