Announcement Announcement Module
Collapse
No announcement yet.
Binding multivalue fields to a command object Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    Turns out this was a problem with my unit test.

    Comment


    • #3
      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, 04:19 AM.

      Comment

      Working...
      X