Announcement Announcement Module
No announcement yet.
Multiple form values with the same name (checkboxes, etc) Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multiple form values with the same name (checkboxes, etc)

    This is the first true stumbling block I've hit with Spring, and I'm sure there is a simple way around it.

    I have a form where a user can edit an employee, and using checkboxes you can assign what departments she/he
    belongs to.

    How can you use spring:bind when you have multiple form values with the same name?

    I want it, so when the user goes in to edit an employee, it will build the list of departments, and check the ones the employee belongs to.

    I hope this makes sense.

    Thanks in advance for your time,


  • #2
    Unfortunately, there's no built-in way (I'm aware of) for this issue. You'll have to override the onBind() method and put some code in it to extract the parameters straight from the request like this:

    protected void onBind(HttpServletRequest request, Object command, BindException errors) {
        String[] employees = request.getParameterValues("_employee");
        // instanciate and set employees in model...
    Note that if you specify the same name for the parameter and the spring:bind you will receive an error because Spring will try to convert a string to you object type (hence the "_").