Results 1 to 1 of 1

Thread: Binding form input to an ArrayList

  1. #1
    Join Date
    Nov 2005
    Location
    Leesburg, VA
    Posts
    11

    Default Binding form input to an ArrayList

    Hi,

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

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

    Actually the JSP looks like:

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

    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 at 02:21 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
  •