6

I do an AJAX request from mt front-end with array as parameter. Example of the array:

arr = [13, 56, 43]

When in Grails controller I print params I get arr[]:[13, 56, 43]. However, when in front-end array consists of only one element (arr = [25], for instance), then in controller I get arr[]:32. However, I need the parameter to be the list, like arr[]:[32]. How can I do that?

  • This do the trick `List myParam = params.list('myParams')` instead of asking if the param is instance of list or not. – IgniteCoders Apr 28 '15 at 14:44

2 Answers2

8

In the controller you can use

params.list('arr[]')

This will always return a list, with zero, one or more than one element, unlike the basic

params.'arr[]'

which gives you null if there are no arr[] parameter values, the single value if there is one, and a list if there is more than one.

Ian Roberts
  • 120,891
  • 16
  • 170
  • 183
0

I think In the controller you can use

List arr = []

arr = params.list

or

def arr
arr = params.list as List
john Smith
  • 17,409
  • 11
  • 76
  • 117