We are having an issue with binding a multiple select element when the option values contain commas. We have tried binding to both a String
and to a List<String>
, but have issues with both.
When a multiple select element is posted, the value of each selected option is passed in a separate request parameter, all with the same name. For example, if the select element name is "code", the parameters might look like this:
code=ABC
code=A,B
code=XYZ
When binding to a String
, Spring will automatically join these values into a comma-separated string. That is obviously an issue if one or more of the values contains a comma.
When binding to a List<String>
, things work fine when multiple options are selected. In that case, Spring creates a List
with an entry for each selected option. But if only one option is selected, Spring assumes the value is a comma-separated list and will split it into multiple entries.
Is there a way to tell Spring to use a different character than a comma when binding to a String
? Is there a way to tell Spring not to split a single value when binding to a List<String>
? Or is there another way to deal with this?