views:

43

answers:

3

Using Grails 1.3.3, when requesting url link:

/myapp/mycontroller/myaction?p1=v1&p2=v2&p1=v1

then params injected value into Grails controller will contain :

assert params.p1== ['v1','v1']

It would have been logical to me that params.p1 equals to 'v1', no?

In any case, is there any way to change this behavior?

Thank you.

A: 

Is this a bug in your app that the parameter is twice? Most people would think that should mean it has multiple values, hence it wouldn't be considered strange behavior. You can always grab the query string and parse it yourself if you don't like the default behavior.

Andrew
+1  A: 

i agree with @Andrew, but of you must

p1.unique()[0] == 'v1'

Aaron Saunders
wouldn't that fail if there was only one parameter (p1) since it won't be an array?
omarello
A: 

I'm assuming you don't want it to pick up the duplicates because you don't want to have to write code in every controller action to handle that special case. The only thing I can tell you is to not allow the duplicates in the first place, or intercept the request using a filter and substitute the duplicate param values.

Javid Jamae