Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

force grails to treat a string parameter as collection of string

In grails, I have a Controller that expects a 'options' parameter that is sent via POST that can be a collection, i.e. 'options=A&options=B&options=C' which gets into grails, thanks to grails magic, as options = Collection of String with value ['A','B','C']. Problem is, when the user only picks one option, then the parameter becomes string and not string[] (or List) and when doing options.each then each, by groovy magic, gets processed character by character... how can I force options to be string[] or List so options.each is applied correctly?

like image 276
carlosayam Avatar asked Jul 04 '11 05:07

carlosayam


1 Answers

In your action, you can always assume it as list like as follows:

List options = params.list('options')

like image 115
Amit Jain Avatar answered Sep 23 '22 02:09

Amit Jain