Announcement Announcement Module
No announcement yet.
Binding a multiple select to a Collection? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Binding a multiple select to a Collection?

    How do I bind a multi-select box to a list of custom objects?

    I have a multi-select, like this:

    <form:select path="countries" multiple="true" size="3">
    	<c:forEach items="${countryList}" var="country">
    		<form:option value="${country.abbreviation}">
    			<spring:message code="${country.key}" />
    And my backing object/command has a field with getters/setters like this:

    private List<Country> countries;
    public List<Country> getCountries() {
    	return countries;
    public void setCountries( List<Country> countries ) {
    	this.countries = countries;
    I've created a custom editor (extends PropertyEditorSupport) that will convert a request parameter String into a Country object, but the "List" part of the binding is not working because the entire string is being passed to my custom Country editor.

    For example, if the countries "United States" and "Canada" are selected, then the request parameter will be "US, CA". Instead of the custom Country editor getting called twice with "US" being passed in first and "CA" second, the entire string ("US, CA") is passed into the custom Country editor.

    I'm starting to look into the CustomCollectionEditor class, but so far have not found any solution. Please help me out as this is really important to my application.


  • #2
    Nevermind, I was using a mock request in a unit test and didn't realize that multiple select were stored in a String[] not a String.


    • #3
      I have similar problem, i need to bind multiple select values to set object. Anybody can help?