Announcement Announcement Module
No announcement yet.
Binding form input to an ArrayList Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Binding form input to an ArrayList


    I'm using the following Spring convention to bind my input values to an ArrayList:

    <input type="text" name="moves[0]" value="">

    Actually the JSP looks like:

    <input type="text" name="moves[<c:out value="${command.currentMove}"/>]" value="<c:out value="${command.moves[command.currentMove]}"/>">

    Where command.currentMove represents the List index

    It works great for the most part. The problem occurs if the user creates a new session, uses the back button to return to this page, and submits the form. Doing so results in the following error:

    org.springframework.beans.InvalidPropertyException : Invalid property 'moves[0]' of bean class [FormBean]:..

    This makes sense since the moves list is now empty. I avoid this situation in normal processing by creating a Move object at the currentMove prior to this page.

    I thought about a couple solutions:

    1. return user to start page in error handler if InvalidPropertyException is caught.

    2. binding form input to String and adding to List in the onBind method.

    3. Adding a new Move object to list at the correct index during the bind process.

    Possibly I am over complicating this - any ideas would be appreciated.
    Last edited by rappa; Nov 30th, 2006, 03:21 PM.