You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Greg Lindholm <gr...@gmail.com> on 2015/05/21 22:37:20 UTC

URL Array parameter encoding arr[]=1&arr[]=2&arr[]=3

Using S2 2.3.16.3

My action wants to take an array of parameters, if they are passed like
arr=1&arr=2&arr=3 then everything works fine.

But by default JQuery encodes arrays as URL parameters like
arr[]=1&arr[]=2&arr[]=3,
the parameters get named "arr[]" instead of "arr".

My action has a setter like:

public void setArr(String[] arr)

This isn't matching the parameter "arr[]" so the setter never gets called.

Is there a way to have Struts recognize that parameters "arr[]" is the same
as array "arr"?

If not, how do I construct a setting that will accept parameters named
"arr[]"?


Greg

P.S. I know how to force jQuery to encode the "traditional" way but would
be nice it just worked.

Re: URL Array parameter encoding arr[]=1&arr[]=2&arr[]=3

Posted by Christoph Nenning <Ch...@lex-com.net>.
> 
> Using S2 2.3.16.3
> 
> My action wants to take an array of parameters, if they are passed like
> arr=1&arr=2&arr=3 then everything works fine.
> 
> But by default JQuery encodes arrays as URL parameters like
> arr[]=1&arr[]=2&arr[]=3,
> the parameters get named "arr[]" instead of "arr".
> 
> My action has a setter like:
> 
> public void setArr(String[] arr)
> 
> This isn't matching the parameter "arr[]" so the setter never gets 
called.
> 
> Is there a way to have Struts recognize that parameters "arr[]" is the 
same
> as array "arr"?
> 
> If not, how do I construct a setting that will accept parameters named
> "arr[]"?
> 
> 
> Greg
> 
> P.S. I know how to force jQuery to encode the "traditional" way but 
would
> be nice it just worked.




You can play with ParameterNameAware, not sure if that would work.
Otherwise you could implement an own interceptor which sets those 
parameters on your action.


Regards,
Christoph

This Email was scanned by Sophos Anti Virus