Results 1 to 2 of 2

Thread: Indexed property problem with list property

  1. #1
    Join Date
    Sep 2004
    Posts
    23

    Default 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
    Code:
    <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 [it.esselunga.ecommerce.services.poll.AnsweredPoll]: 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?

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

  2. #2
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    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:

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

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

    For more info checkout: (self promotion ) http://forum.springframework.org/showthread.php?t=17646
    Last edited by robyn; May 14th, 2006 at 10:08 AM.

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  3. Replies: 4
    Last Post: Aug 17th, 2005, 04:42 AM
  4. Odd behaviour when injecting TransactionTemplate
    By damon311 in forum Container
    Replies: 3
    Last Post: Jul 23rd, 2005, 11:21 AM
  5. Replies: 2
    Last Post: May 13th, 2005, 05:42 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
  •