Preferred patterns for accepting lists of String inputs

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Preferred patterns for accepting lists of String inputs

Joe Adams-2
This isn't a super hard problem but I'm wondering how people go about solving it.

I form input that is a list of Strings (although I can make it an array if that would work better).  I have a select box to choose the number of inputs.  Then I use JavaScript to create the input text boxes.   (I also want to be able to pre-populate the input boxes with values.)

I tried making it an array of Strings named inputs and then I'd make the input box have the name "inputs".  It sometimes works, but it seems to cut off the extra values.

I'm also working on making it a list and naming the inputs "input[0]", "input[1]", etc.  This works, but it seems like a more work than is necessary.

How do others solve this problem?

Thanks,
Joe

------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Preferred patterns for accepting lists of String inputs

VANKEISBELCK Remi
<base href="x-msg://107/">Hi Joe,

I've had this choice to make a few weeks ago... I needed to pass two different data structures for processing on the server, sent from JS code (AJAX).

I've used Stripes binding in one case (for Maps, but works for Lists too), with the big advantage that Stripes' form repop (which you want), type converters, validation and all that jazz works directly on Map (or list) elements, even with user datatypes (provided you register the type converters of course) :

POST /my.action?myMap[0]=1&myMap[1]=2... 
binds on 
Map<Integer,MyClass>

In an other, more complex case with more than a Map to get on the server, using JSON seemed to be better.

POST /my.other.action?myData={ // JSON string here }&...
... and use JsonSlurper (or any lib) on the server : here I needed to do all the validation, resolve user objects, etc. I just did it that way because binding a very complex Map<List<Map<Whatever,Shit>,Dam>Really> was too complex using Stripes binding.

So I'd say that Stripes binding is usually better. It makes everything really simpler on the server side. You just need to construct the appropriate request params that's all. 
IMO binding is one of the very the best parts in Stripes... enjoy without reserve :)

Cheers

Rémi

Le 12 févr. 2013 à 22:54, Joe Adams a écrit :

This isn't a super hard problem but I'm wondering how people go about solving it.

I form input that is a list of Strings (although I can make it an array if that would work better).  I have a select box to choose the number of inputs.  Then I use JavaScript to create the input text boxes.   (I also want to be able to pre-populate the input boxes with values.)

I tried making it an array of Strings named inputs and then I'd make the input box have the name "inputs".  It sometimes works, but it seems to cut off the extra values.

I'm also working on making it a list and naming the inputs "input[0]", "input[1]", etc.  This works, but it seems like a more work than is necessary.

How do others solve this problem?

Thanks,
Joe
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users


------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users