carlosayam
carlosayam

Reputation: 1398

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?

Upvotes: 18

Views: 11908

Answers (1)

Amit Jain
Amit Jain

Reputation: 1382

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

List options = params.list('options')

Upvotes: 34

Related Questions