Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've tested your code: it's unbelievable, but I can't reproduce your issue. I've downloaded the latest version of spring (3.0.5), this is my controller:</p> <pre><code>package test; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.springframework.stereotype.Controller; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @Controller @RequestMapping("/test/**") public class MyController { private static final Logger logger = Logger.getLogger(MyController.class); @RequestMapping(value = "/test/params", method = RequestMethod.GET) public void test(SearchRequestParams requestParams, BindingResult result) { logger.debug("fq = " + StringUtils.join(requestParams.getFq(), "|")); } } </code></pre> <p>this is my SearchRequestParams class:</p> <pre><code>package test; public class SearchRequestParams { private String[] fq; public String[] getFq() { return fq; } public void setFq(String[] fq) { this.fq = fq; } } </code></pre> <p>and this is my simple spring configuration:</p> <pre><code>&lt;bean id="urlMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /&gt; &lt;bean class="test.MyController" /&gt; &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt; &lt;property name="prefix"&gt; &lt;value&gt;/WEB-INF/jsp/&lt;/value&gt; &lt;/property&gt; &lt;property name="suffix"&gt; &lt;value&gt;.jsp&lt;/value&gt; &lt;/property&gt; &lt;/bean&gt; </code></pre> <p>I've tested my code within tomcat 7.0.8; when I type <code>http://localhost:8080/testweb/test/params.htm?fq=foo,bar</code> I'm able to read in my log file this line: <code>DEBUG fq = foo,bar</code>. What are the the differences from my code to yours? Am I doing something wrong? I'd like to help you, so if you have any doubts or if I can do some other tests for you, it will be a pleasure.</p> <p><strong>UPDATE / SOLUTION</strong><br> With your code I've reproduced the issue; you have the tag <code>&lt;mvc:annotation-driven /&gt;</code> in your dispatcher servlet configuration, so you silently use a default conversion service, instance of <code>FormattingConversionService</code>, which contains a default converter from <code>String</code> to <code>String[]</code> that uses comma as separator. You have to use a different conversion service bean containing your own converter from <code>String</code> to <code>String[]</code>. You should use a different separator, I've choosed to use ";" because it's the separator commonly used into query string ("?first=1;second=2;third=3"):</p> <pre><code>import org.springframework.core.convert.converter.Converter; import org.springframework.util.StringUtils; public class CustomStringToArrayConverter implements Converter&lt;String, String[]&gt;{ @Override public String[] convert(String source) { return StringUtils.delimitedListToStringArray(source, ";"); } } </code></pre> <p>Then you have to specify this conversion service bean in your configuration:</p> <pre><code>&lt;mvc:annotation-driven conversion-service="conversionService" /&gt; &lt;bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean"&gt; &lt;property name="converters"&gt; &lt;list&gt; &lt;bean class="au.org.ala.testspringbinding.CustomStringToArrayConverter" /&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; </code></pre> <p>The issue has fixed, now you should check for any side effects. I hope you don't need in your application the original conversion from <code>String</code> to <code>String[]</code> (with comma as separator). ;-) </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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