Announcement Announcement Module
No announcement yet.
Indexed property problem with list property Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Indexed property problem with list property

    Hello, there is something I don't understand with indexed properties. I have a form backing object representing a "Poll" that contains a List of "Answers". When I'm showing the form I populate it with a number of Answers objects, which results in a number of
    <input type="radio" name="answers&#91;0&#93;.choiceId" value="125"                                                    id="response125" />option
    in my form. When I'm submitting the form, though, I get an exception like this:
    org.springframework.beans.InvalidPropertyException : Invalid property 'answers[0]' of bean class []: Index of out of bounds in property path 'answers[0]'; nested exception is java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    I've followed the code and I see that in fact it tries to set the value on my list after creating the form object (which results in an empty list), and without adding it to the list, but directly setting it by index (which causes the error). Does this mean that my only two options are:
    1) putting the form in the session on show and reuse it on submit with a correct number of answers
    2) leaving the form in the request but receiving a value indicating how many answers must the form have and override formBackingObject so that the form object contains that number of answers?

    p.s.: I'm stuck with Spring 1.0.2, for now, maybe this has changed in a later version?

  • #2
    Basically yes, they are the two options.

    As you mentioned, spring won't bind to the List, it binds to the elements of the List. On the other hand, spring *will* bind to an array, i.e. at the moment spring will call:

      command.getList().set(0, property);
      command.getList().set(1, property);
    if you use an Array, spring will do:

      command.setArray(String[] values);
    which might be more suitable.

    For more info checkout: (self promotion )
    Last edited by robyn; May 14th, 2006, 10:08 AM.