Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7526047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:43:34+00:00 2026-05-30T03:43:34+00:00

I’m using a multiple select HTML form input to allow a user to pick

  • 0

I’m using a multiple select HTML form input to allow a user to pick a collection of Extensions from a list of all possible Extensions.

The Extension class is quite simple –

public class Extension {

 private String number;
 private String firstName;
 private String lastName;

 ... getters and setters ...

 @Override
 public String toString() {     
  return new StringBuilder(number).append(" - ")
               .append(firstName).append(" ").append(lastName)
               .toString();
 }  

}

Here’s my form object –

public class BusinessUnitForm {

    private String name;
    private Collection<Extension> extensions;


    public Collection<Extension> getExtensions() {
        return extensions;
    }

    public void setExtensions(Collection<Extension> extensions) {
        this.extensions = extensions;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}

And the controller –

@Controller
@RequestMapping("/businessunit")
public class BusinessUnitController {

    ... extension service & getters/setters ...

    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView showForm(HttpServletRequest request, HttpServletResponse response) throws Exception {

        Integer customerId = (Integer) request.getSession().getAttribute("customerId");
        ModelAndView mav = new ModelAndView("bu");

        // this is quite expensive...
        Collection<Extension> allExtensions = extensionService.getAllExtensions(customerId);

        BusinessUnitForm businessUnitForm = new BusinessUnitForm();

        mav.addObject("allExtensions", allExtensions);
        mav.addObject("businessUnitForm", businessUnitForm);

        return mav;
    }

    @RequestMapping(value="/create", method = RequestMethod.POST)
    public ModelAndView create(HttpServletRequest request, HttpServletResponse response, BusinessUnitForm businessUnitForm, BindingResult result) throws Exception {

        // *** BREAKPOINT HERE *** to examine businessUnitForm 

        Integer tenantId = (Integer) request.getSession().getAttribute("tenantId");

        // code to process submission 

        ModelAndView mav = new ModelAndView("bu"); 
        return mav;
    }
}

And finally the view –

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>

<html>

...

<form:form action="businessunit/create" method="POST" commandName="businessUnitForm" >

 <form:label path="name"></form:label><form:input path="name" />

 <form:select path="extensions" cssClass="multiselect">                      
  <form:options items="${allExtensions}" itemValue="number" />
 </form:select>

 <input type="submit" value="Create" />

</form:form>

...

</html>

At the breakpoint shown above in the create controller method, businessUnitForm.extensions is null. businessUnitForm.name is bound correctly.

I’ve tried, perhaps misguidedly, making businessUnitForm.extensions a LazyList but this doesn’t help.

If I change BusinessUnitForm.extensions to be a Collection of unspecified type, it is populated successfully with a LinkedHashSet of Strings, containing the values selected.

Maybe I’m expecting too much of Spring, but I was hoping it would be able to use the values from the select, and also the reference data in allExtensions to automagically create a Collection<Extension> for me on the businessUnitForm. I understand the role of CustomCollectionEditors, but was under the impression that this might not be required in Spring 3.

Can Spring 3 populate my Collection<Extension> on the BusinessUnitForm without me writing a custom collection editor ? Some kind of trick with the view, perhaps ?

Thanks in advance …

Dan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T03:43:35+00:00Added an answer on May 30, 2026 at 3:43 am

    You need to implement a custom converter that is able to convert the String from the request into an Extension object.

    And then you must use Collection (or List, or Set) with generic type information.

    See this answer for an example of an converter: Submit Spring Form using Ajax where Entity has Foreign Entities

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.