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.
Up vote 19 down vote favorite 5 share g+ share fb share tw.
Consider the following controller method: @RequestMapping(value = "/test", method = RequestMethod. GET) public void test(@RequestParam(value = "fq", required = false) String filterQuery) { logger. Debug(fq = " + StringUtils.
Join(filterQuery, "|")); } Here is the output for different fq combinations: /test? Fq=foo results in fq = foo /test? Fq=foo&fq=bar results in fq = foo|bar /test?
Fq=foo,bar results in fq = foo|bar /test? Fq=foo,bar&fq=bash results in fq = foo,bar|bash /test? Fq=foo,bar&fq= results in fq = foo,bar| Example 3 is the problem.
I expect (want/need) it to output fq = foo,bar. I've tried escaping the comma with \ and using %3C but niether work. If I look at the HttpServletRequest object's version: String fqs = request.
GetParameterValues("fq"); logger. Debug(fqs = " + StringUtils. Join(fqs, "|")); It prints the expected output: fqs = foo,bar.
So the "problem" is with the Spring data binding. I could by-pass Spring's binding and use HttpServletRequest but I really don't want to as I'm using a backing bean 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.
TIA UPDATE: I posted this Q on Twitter and got a reply saying the expected output appears with Spring 3.0.4.RELEASE. 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. Java spring data-binding spring-mvc link|improve this question edited Apr 1 '11 at 13:09javanna4,85431021 asked Feb 15 '11 at 0:03nickdos1,315613 89% accept rate.
1 Logged as bug: jira.springsource.org/browse/SPR-7963 – nickdos Feb 15 '11 at 5:44 1 I suggest you add your resolution as an answer to your own question to make it clearer to others that you have found a solution. – Philip Potter Mar 6 '11 at 8:41 Thanks for the suggestion Phillip. It turns out that the fix of using 3.0.4 works for @RequestMapping but does NOT fix the same issue when binding to a form-backing bean.
So I've not got a fix for my application yet. I've still not got a comment/update on the Spring Jira issue yet - which is a bit slack of them I think. – nickdos Mar 6 '11 at 10:11.
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: 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(), "|")); } } this is my SearchRequestParams class: package test; public class SearchRequestParams { private String fq; public String getFq() { return fq; } public void setFq(String fq) { this. Fq = fq; } } and this is my simple spring configuration: /WEB-INF/jsp/ .
Jsp I've tested my code within tomcat 7.0.8; when I type http://localhost:8080/testweb/test/params. Htm? Fq=foo,bar I'm able to read in my log file this line: DEBUG fq = foo,bar.
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.
UPDATE / SOLUTION With your code I've reproduced the issue; you have the tag in your dispatcher servlet configuration, so you silently use a default conversion service, instance of FormattingConversionService, which contains a default converter from String to String that uses comma as separator. You have to use a different conversion service bean containing your own converter from String to String. 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"): import org.springframework.core.convert.converter. Converter; import org.springframework.util. StringUtils; public class CustomStringToArrayConverter implements Converter{ @Override public String convert(String source) { return StringUtils.
DelimitedListToStringArray(source, ";"); } } Then you have to specify this conversion service bean in your configuration: 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 String to String (with comma as separator). ;-).
Thanks for that. The code you pasted is basically what I'm using. I've still got the controller method in my webapp and I just tried it again and still see the "foo|bar" in my version.
I'm now wondering if I'm getting one of those strange maven dependency problems as I have a dependency on a project that uses an older version of Spring. I'll make a brand new "bare" Spring project and try it out and report back. – nickdos Mar 9 '11 at 1:00 I just created a new Maven webapp (JEE 6) with Spring MVC 3.0.5 support (using Netbeans).
I modified the pom a bit and created two classes as per this answer. Ran the webapp in both Jetty and tomcat (6.0.20) and I still get the output fq = foo|bar (I have the output going to the browser now). I've put the code up on Google Code here: svn checkout ala-hubs.googlecode.com/svn/trunk/testSpringBinding - would love to get to the bottom of this... – nickdos Mar 9 '11 at 3:26 Well, I'm glad to help you, let me see your code.
I will post some news in a few hours. – javanna Mar 9 '11 at 14:35 I've edited my answer, have fun! – javanna Mar 9 '11 at 21:54 Many thanks Javanna.
I hope you get the 50 point bounty. – nickdos Mar 9 '117 at 5:46.
As suggested by Philip Potter, I'm posting the "update" to my question as an answer, as it might've been easy to miss... Down-grading from Spring 3.0.5. RELEASE to 3.0.4. RELEASE fixed the issue, when using the @RequestParam annotation, suggesting it is a bug with 3.0.5.
However, it does NOT fix the related issue, when binding to a form-backing bean - which is what I have in my webapp. I've tested all version back to 3.0.0. RELEASE and get the same result (/test?
Fq=foo,bar produces fq = foo|bar). E.g. @RequestMapping(value = "/test", method = RequestMethod.
GET) public void test(SearchRequestParams requestParams, BindingResult result) { logger. Debug("fq = " + StringUtils. Join(requestParams.getFq(), "|")); } where SearchRequestParams contains a field String fq.
If anyone has a fix for this, I'll gladly accept their answer.
Fq=foo-bar&fq=bash results in fq = foo-bar|bash Or any other delimiter maybe ~, or! ,or ^, or?
1 The parameter values come from Solr facets - and although I could munge them at index time to replace the comma with something_else, it is too much extra effort for what is, I agree, a hack. – nickdos Mar 7 '11 at 8:36.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.