Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to prevent parameter binding from interpreting commas in Spring 3.0.5?
    text
    copied!<p>Consider the following controller method:</p> <pre><code>@RequestMapping(value = "/test", method = RequestMethod.GET) public void test(@RequestParam(value = "fq", required = false) String[] filterQuery) { logger.debug(fq = " + StringUtils.join(filterQuery, "|")); } </code></pre> <p>Here is the output for different <code>fq</code> combinations:</p> <ol> <li><code>/test?fq=foo</code> results in <code>fq = foo</code> </li> <li><code>/test?fq=foo&amp;fq=bar</code> results in <code>fq = foo|bar</code> </li> <li><code>/test?fq=foo,bar</code> results in <code>fq = foo|bar</code> </li> <li><code>/test?fq=foo,bar&amp;fq=bash</code> results in <code>fq = foo,bar|bash</code> </li> <li><code>/test?fq=foo,bar&amp;fq=</code> results in <code>fq = foo,bar|</code></li> </ol> <p>Example 3 is the problem. I expect (want/need) it to output <code>fq = foo,bar</code>.</p> <p>I've tried escaping the comma with <code>\</code> and using <code>%3C</code> but niether work. </p> <p>If I look at the <code>HttpServletRequest</code> object's version:</p> <pre><code>String[] fqs = request.getParameterValues("fq"); logger.debug(fqs = " + StringUtils.join(fqs, "|")); </code></pre> <p>It prints the expected output: <code>fqs = foo,bar</code>. So the "problem" is with the Spring data binding.</p> <p>I could by-pass Spring's binding and use <code>HttpServletRequest</code> but I really don't want to as I'm using a <strong>backing bean</strong> in my real code (same thing is happening) and don't wish to re-implement the binding functionality. I'm hoping someone can provide a simple way of preventing this behavior via escaping or some other mechanism.</p> <p>TIA</p> <p><strong>UPDATE:</strong> I posted this Q on Twitter and got a reply saying <strong>the expected output appears with Spring 3.0.4.RELEASE</strong>. I've now confirmed this is the case and thus is a temporary fix. I'll go ahead and log this as a bug on the Spring JIRA system. If anyone can provide a work around or fix with 3.0.5, I'll accept their answer.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload