Results 1 to 3 of 3

Thread: Binding multivalue fields to a command object

  1. #1
    Join Date
    Aug 2004
    Posts
    25

    Default Binding multivalue fields to a command object

    I've searched the form and haven't found an answer to this question.

    Let's say that a SimpleFormController receives a POST that looks like this:

    foo=value1
    bar=value2
    bar=value3
    bar=value4

    I have a command class that looks like this:

    Code:
    public class MyCommand
    {
        private String[] foo;
        private String[] bar;
    
        public void setFoo(String[] foo) { this.foo = foo; }
        public String[] getFoo() { return foo; }
    
        public void setBar(String[] bar) { this.bar = bar; }
        public String[] getBar() { return bar; }
    
    }
    Ignore any syntax errors in that code, I just typed it in by hand as an example.

    The question is, how do I get value2, value3, and value4 to appear as elements of the array bar[] in my code? Right now, binding assigns "value1" to "foo" (correct) and "value2" to "bar". Even more oddly, if I had:

    bar=new york, ny
    bar=value3
    bar=value4

    In my command object, I wind up with "bar" containing two elements, "new york" and "ny".

    What am I missing?

  2. #2
    Join Date
    Aug 2004
    Posts
    25

    Default

    Turns out this was a problem with my unit test.

  3. #3
    Join Date
    Aug 2004
    Posts
    25

    Default

    I did find a related binding problem that's caused by StringArrayPropertyEditor, which I posted about here:

    http://forum.springframework.org/showthread.php?t=15400
    Last edited by robyn; May 16th, 2006 at 04:19 AM.

Similar Threads

  1. Replies: 1
    Last Post: Sep 22nd, 2005, 04:42 AM
  2. Replies: 7
    Last Post: Sep 13th, 2005, 01:45 AM
  3. Date binding from 3 text fields
    By Sergei Rogovskiy in forum Web
    Replies: 1
    Last Post: Apr 19th, 2005, 06:10 AM
  4. Replies: 1
    Last Post: Mar 23rd, 2005, 06:59 AM
  5. Replies: 2
    Last Post: Aug 17th, 2004, 04:16 PM

Posting Permissions

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