Best Practice to submit multiple rows of data

244 views
Skip to first unread message

green

unread,
Feb 23, 2010, 2:20:38 AM2/23/10
to play-fr...@googlegroups.com
Hi 

What do you use to submit multiple records? A typical use case is that an order creation form will have several order items data input by the end user.  My approach is as follows:

At the client side: Put an hidden field in the <form> like <input type='hidden' name='items'/>. User add order items either through multiple predefined input fields or dynamically generated fields using javascript. Hook a event handler to form.submit event, construct a string with all order items information using special separator e.g. ';', update the hidden items field with the calculated string val. Then proceed with the submission process.

At the server side, parse the item string and construct order items object on the fly, add them into a new order model and save it.

Does anyone has better approach with Play!

Thx,
Green

Guillaume Bort

unread,
Feb 23, 2010, 6:24:43 AM2/23/10
to play-fr...@googlegroups.com
Play support multiple values that you can then bind as Array or List.
But anyway it is always difficult to map complex data structure (with
repeat) into URL form encoded representation.

Perhaps you could do it using Ajax and JSON?

> --
> You received this message because you are subscribed to the Google Groups
> "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to
> play-framewor...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/play-framework?hl=en.
>

green

unread,
Feb 23, 2010, 9:25:18 AM2/23/10
to play-fr...@googlegroups.com
Yes I am using JSON to encode the data passed to server. With regarding to AJAX, it is a beautiful technology but not suit for my case because: 
1. performance consideration: I don't want each time user change the value in a text box trigger an update to the server
2. user experience: I think it is good to let end user to explicitly click 'submit' and then data get saved in the database. That explicit 'submit' button gives user a good indication of what he/she is doing.

BTW, appreciate the response!

Guillaume Bort

unread,
Feb 23, 2010, 11:31:06 AM2/23/10
to play-fr...@googlegroups.com
Using ajax does not mean that you need to send a request to the server
each time the user modify a field in the form. Just wait for the form
submission and send the JSON... But it's right that you can encode
your data in JSON into an hidden field too.

green

unread,
Feb 23, 2010, 5:24:34 PM2/23/10
to play-fr...@googlegroups.com
Talking about JSON, in the server side, I use gson (which is already included in play framework) to parse the data. Not sure if play has other utilities for that.
Reply all
Reply to author
Forward
0 new messages