Using DynamicForm and ObjectNode with Scala

608 views
Skip to first unread message

Stefano Di Martino

unread,
Jun 11, 2013, 12:22:05 PM6/11/13
to play-fr...@googlegroups.com

I'm porting a Play application written in Java to Scala. I had no problems until I stuck with DynamicForm. I just can't find this class in the Scala version of Play. There is no such thing like DynamicForm. How would you port this code to Scala?!

DynamicForm data = form().bindFromRequest();


The next problem arises when I use ObjectNode:

ObjectNode respJSON = Json.newObject();
//...
return ok(respJSON);

Ported to this:

var respJSON = Json.newObject
//...
Ok(respJSON)


Following error occurs on the last line (Ok(respJSON)):

Cannot write an instance of org.codehaus.jackson.node.ObjectNode to HTTP response. Try to define a Writeable[org.codehaus.jackson.node.ObjectNode]


Anyone, who could help me?

Thanks in advance!
Stefano

Stefano Di Martino

unread,
Jun 11, 2013, 12:39:25 PM6/11/13
to play-fr...@googlegroups.com
Btw: I'm using Play 2.1.1 and Scala 2.10

Stefano Di Martino

unread,
Jun 11, 2013, 2:43:23 PM6/11/13
to play-fr...@googlegroups.com
This seems to work for DynamicForms, but I can't test it, because the second error still appears:

import play.data.DynamicForm
//...
val data = new DynamicForm().bindFromRequest()


As I said, the second Json error still appears. Any ideas?

Thx in advance!
Stefano

Stefano Di Martino

unread,
Jun 12, 2013, 2:11:29 PM6/12/13
to play-fr...@googlegroups.com
Hi,
I had now the possibility to test this code and it doesn't work!

java.lang.RuntimeException: There is no HTTP Context available from here.

Actually I don't really need the Java DynmaicForm but an equivalent(!) of it!
Anyone any idea?!

Best regards!
Stefano

PS: The Json problem is solved.

Guillaume Bort

unread,
Jun 12, 2013, 2:34:25 PM6/12/13
to play-fr...@googlegroups.com

It depends of what you are actually trying to do.

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Message has been deleted

Stefano Di Martino

unread,
Jun 13, 2013, 4:10:15 AM6/13/13
to play-fr...@googlegroups.com
I want to read values from a HTML form (type = submit). The form is written in pure HTML!
In Java this is done in the following way:

DynamicForm data = form().bindFromRequest();
String foo = data.get("my-input-id");


Thx in advance for help!

Regards
Stefano

Guillaume Bort

unread,
Jun 13, 2013, 4:18:04 AM6/13/13
to play-fr...@googlegroups.com
Either use the Form API for that:

val f = form(
  "my-input-id" -> text
)

f.bindFromRequest()

Or access directly the body data using request.body.asUrlFormEncoded
--
Guillaume Bort, http://guillaume.bort.fr

Stefano Di Martino

unread,
Jun 13, 2013, 9:44:33 AM6/13/13
to play-fr...@googlegroups.com
I used request.body.asUrlFormEncoded - thx a lot!!! :)
Reply all
Reply to author
Forward
0 new messages