Results 1 to 2 of 2

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

  1. #1
    Join Date
    Aug 2004
    Posts
    11

    Default 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,

    Josh

  2. #2
    Join Date
    Aug 2004
    Location
    Montreal, Canada
    Posts
    35

    Default

    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:

    Code:
    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 "_").

    Uze

Similar Threads

  1. Replies: 3
    Last Post: Jun 8th, 2010, 03:27 AM
  2. MySQL DDL
    By analogueboy in forum Security
    Replies: 5
    Last Post: Aug 17th, 2007, 03:48 PM
  3. Multiple Values (Checkboxes, etc)
    By stateofmind in forum Web
    Replies: 1
    Last Post: Jun 16th, 2005, 02:46 PM
  4. Replies: 2
    Last Post: May 5th, 2005, 09:35 PM
  5. Replies: 4
    Last Post: Jan 21st, 2005, 08:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •