Results 1 to 9 of 9

Thread: Binding dynamic forms

  1. #1
    Join Date
    Jul 2005
    Posts
    1

    Default Binding dynamic forms

    Hi,

    There are a lot of threads here about binding dynamic forms to the Command object but I haven't been able to find a real, concrete, clean solution anywhere.

    Example scenerio:

    I have a command object that has a list of string values. I generate my form and each string value in my list is shown as a textbox. I also have form buttons to add/remove textboxes to/from the form through JavaScript. I add new textboxes and remove some too.

    When I submit the form, how do I handle binding the form elements to my command?

    Is the best solution to use a custom data binder?

  2. #2
    Join Date
    Aug 2007
    Posts
    12

    Default

    Is there a solution for this..?? i searched on on the threads and found this old thread which exactly is my problem...i have a page where i add textboxes dynamically through javascript..when i submit how to bind these values ??

  3. #3
    Join Date
    Mar 2006
    Posts
    312

  4. #4
    Join Date
    Aug 2007
    Posts
    12

    Default

    Quote Originally Posted by jglynn View Post
    yeah i have visited this link before...the problem here is how to bind the dynamically generated input tags (added through clientside javascript and dhtml) to spring form/command object...

  5. #5
    Join Date
    Mar 2006
    Posts
    312

    Default

    If you name them appropriately I believe Spring will bind them.

  6. #6
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

    Quote Originally Posted by jglynn View Post
    If you name them appropriately I believe Spring will bind them.
    That's true since only the request parameter names matter at the end. The only problem is accessing an index in the list that does not yet exist on the server (more items added on the client). It can be solved with LazyList.

    Joerg
    This post can contain insufficient information.

  7. #7
    Join Date
    Jan 2008
    Posts
    22

    Default how can i dynamicly delete records?

    Hi,
    I used the LazyList and it works great for adding new records:
    with javascript i add new records and they get binded by spring.
    My problem is that i want to allow delete record option as well,
    i can make it work by overide onBindAndValidate and i read of another solution which use propertyEditor.
    apache TreeList sounds intresting:
    http://commons.apache.org/collection.../TreeList.html
    but i could make it work,couldn't find example.

    Is someone aware of a more elegant solution?
    Thanks.

  8. #8
    Join Date
    Jul 2008
    Posts
    1

    Red face Add fields on update function does not bind values

    Quote Originally Posted by Jörg Heinicke View Post
    That's true since only the request parameter names matter at the end. The only problem is accessing an index in the list that does not yet exist on the server (more items added on the client). It can be solved with LazyList.

    Joerg
    Hi, I'm not sure if I lack somethings in my codes but I am still encountering problem even if I'm using the LazyList.

    My scenario is same with others, I have text box which can be added and deleted using javascript. I have already read this: Dynamic list binding in Spring MVC by matt fleming

    For clarity, I have for example a Type bean with list of Subtype. Subtype has name as property. In my add page, I could add names (text fields) and this works. The names are set and Subtype list binding is working properly. The problem is when I'm in my edit page and I have already displayed the Type details (containing list of Subtypes, say count is 4) and I click the add subtype button (in edit page, still can add Subtype) so now the count is 5. But once I submit the page I'm having error similar to this:

    ..Index of out of bounds in property path 'subType[4]'.. (last added element).

    Am I missing something? At my add page the dynamic adding of text fields is working fine, but on edit it's not? Maybe because on edit there's already bound command (Type)? I've read some post here that access the request and see the count of added fields, and from that re-create lacking object (or something like that) against the original count in the formBackingObject() method. Is there a more elegant/better solution than this?

    Just for info, I'm relatively new in Spring and I appreciate any advice on this. Thanks in advance.

  9. #9
    Join Date
    Jan 2008
    Posts
    22

    Talking LazyList for editing...

    Hi,

    i'm using the same page for adding and editing , having no problem.
    i think that if on your add page you can add items to the list and they get binded , you shouldn't have problem with editing:
    what maks me think that you are not using the same instance
    of object containing your list , is that possible?
    check for the instance address.
    in my page i have a table date column and i can add/edit/delete records.each record is represented by two <tr> one for display and another for editing:
    <code>
    <c:forEach items="${myList[command.index].date}" var="curr" varStatus="st">
    <tr id="tr_${st.index}">
    <td><fmt:formatDate value="${curr}" /></td>
    <td>
    <input type="button" onclick="editLine('_tr_${st.index}','<%=tableId%>' )" PATH="../../../" IMG="but_Pen16x16"/>
    <input type="button" onClick="deleteRow()" PATH="../../../" IMG="but_Delete16x16" />
    <input type="button" onclick="deleteUndo()" PATH="../../../" IMG="but_Undo16x16" />
    <input id="toDelete_${st.index}" type="hidden" name="myList[command.index].row[${st.index}].toDelete" value='false'/>
    <input id="indexInList_${st.index}" type="hidden" name="myList[command.index].row[${st.index}].indexInList" value="${st.index}" />
    </td>
    </tr>
    <tr id="tr_hidden_${st.index}" style="display: none;">
    <td><input type="text" name="myList[command.index].date[${st.index}]" value="<fmt:formatDate value="${curr}" />" id="input_${st.index}" /></td>
    <td>
    <input type="button" onclick="confirmLine('tr_${st.index}','<%=tableId% >')" PATH="../../../" IMG="but_v16x16" />
    <input type="button" onClick="deleteRow()" PATH="../../../" IMG="but_Delete16x16" />
    <input type="button" onclick="deleteUndo()" PATH="../../../" IMG="but_Undo16x16" />
    </td>
    </tr>
    </c:forEach>
    </code>

    Thats as far as edit,for new records keep your name attribute with the same binding.
    i hope it's giving you some progressing...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •