user2782001
user2782001

Reputation: 3488

Grails params.list() does not work

I pass a series of id parameters in the query part of the uri

 ...?id=12&id=16&id=34

This comes into the grails controller and is organized by grails into a list

id:[12,16,34]

but the property is still treated as a string by groovy, so it means this

id:"[12,16,34]"

The documentation advises that if only one is passed then grails won't form a list, so to always use the params.list() method to ensure you get a list

def ids=params.list('id');

But doing that gives me

[ "[12,16,34]" ]

I can't seem to figure out how to get groovy to treat the property as a list once grails as automatically organizes it as a list.

Upvotes: 0

Views: 1238

Answers (1)

trd3v3lop
trd3v3lop

Reputation: 343

Try to send params with POST method and get them by request.JSON or you can split it and assign it to a list. As I know and experience params only returns string.

params.id.toString().split('\\[')[1].split(']')[0]

Upvotes: 1

Related Questions