0

Grails 1.3.1

I am using a jQuery library that sends a serialized parameter map to the server and it is formatted like so....

item[]=1&item[]=2&item[]=3

In my controller, when I do println params, it comes out...

[item[]: [1, 2, 3]]

I can't seem to get this data out of params in my controller, however. What am I missing?

Gregg
  • 34,973
  • 19
  • 109
  • 214

2 Answers2

1

An HTTP Post sends name/value pairs up to the web server. These names are based on the names within the given HTML form controls.

When duplicates exist, they're combined into a comma delimited list of values.

So, "item=1&item=2&item=3" becomes "item=1,2,3" on the server side. You can create an array from the comma delimited string and use the values. This is how you'll process selected items from a tag that allows multiple items to be selected.

If you want to keep the values separate, they'll have to use different names on your HTML form tags.

a7drew
  • 7,801
  • 6
  • 38
  • 39
  • Yes, I understand how that works. The problem I'm having is how to get the array from the params. params.item returns null. – Gregg Jun 29 '10 at 18:23
0

This worked...

params['items[]']

Gregg
  • 34,973
  • 19
  • 109
  • 214