Announcement Announcement Module
Collapse
No announcement yet.
Binding to Dynamic Lists Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Binding to Dynamic Lists

    Hello everyone, I have been looking through the forums and been unable to find simple solution to my problem (maybe there is none). I have a table of inputs for the user. Each row consists of 3 columns of textboxes: id, name, and description. The list is populated from a list in my command, so I don't know how many rows the user will see. Here in lies my problem.

    I need to be able to bind to each of these rows, but have not found a simple Spring method to do so. Here is my current state... this works well, but want all of your input for other possible solutions.
    Code:
    <% int row = 0; %>
    <input type="hidden" id="hidden_rows_dispayed" value="<c&#58;out value="$&#123;myCommand.recordCount&#125;"/>"/>
    <table>
    <c&#58;forEach items="$&#123;myCommand.records&#125;" var="record">
    	<% row++; %>
    	<tr>
    		<td>					
    			<input type="text" id="myId_<%=row%>" value="$&#123;record.id&#125;"/>
    		</td>
    		<td>					
    			<input type="text" id="myName_<%=row%>" value="$&#123;record.name&#125;"/>
    		</td>
    		<td>					
    			<input type="text" id="myDescription_<%=row%>" value="$&#123;record.description&#125;"/>
    		</td>
    	</tr>
    </c&#58;forEach>		
    </table>
    as you can see, I simply append a number on the end of each input's id so I can get to it later. Here is my onSubmit method which gets called after a user saves the table:
    Code:
    int rowCount = RequestUtils.getIntParameter&#40;request, "hidden_rows_displayed", 0&#41;;
    for &#40;int index = 1; index <= rowCount; index++ &#41; &#123;
    	int myId = RequestUtils.getIntParameter&#40;request, "myId_"+index, 0&#41;&#41;;
    	String name = RequestUtils.getStringParameter&#40;request, "myName_"+index, 0&#41;&#41;;
    	String description = RequestUtils.getStringParameter&#40;request, "myDescription_"+index, 0&#41;&#41;;
    	// give the data to whoever needs it
    &#125;
    So, there you have it. I wouldn't really call it "binding," but it seems like the best way I have found. Have any of you found a way to utilize Spring's Binding for dynamic lists? If so, please let me know, it would be awesome if I could get that method to work.

    Thanks,
    Ryan

  • #2
    http://forum.springframework.org/showthread.php?t=17646 might be helpful.
    Last edited by robyn; May 14th, 2006, 10:06 AM.

    Comment


    • #3
      thanks for the pointer... it seems like you are all over this message board, which is Awesome! I like your example, but I am having trouble understanding is how I could adapt that solution to this one.

      My understanding of property editors is that the setText method can only take a single string input. So for my case, I could register my Record class with the binder, then how would is pass all three values to my Record Property Editor?

      Or, is this the case where I can use the setValue method of the propertyeditors? This seems like it could be passed an object... although I have not found much info on this... so is this a possible solution?

      just a bit confused

      Comment


      • #4
        Spring has native "special" support for handling Lists. Basically you register your property editor for your Class, *not* the List.class.

        Checkout http://static.springframework.org/sp...PropertyEditor)

        P.S. Being "all over" this forum does not in any way mean I am right : http://forum.springframework.org/showthread.php?t=18457
        Last edited by robyn; May 14th, 2006, 07:18 PM.

        Comment


        • #5
          ha, thanks for the info I'll check it out and post back if I find anything

          Comment

          Working...
          X