Announcement Announcement Module
Collapse
No announcement yet.
Binding 1-N relations Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Binding 1-N relations

    I defined Orders which contains a Collection of OrdersDetail. Trying to update both Orders and related OrdersDetail in a single form:

    Code:
    <form name="ordersMaintainForm" method="post" action="<c:url value="/orders/viewOrders.htm"/>">
    	<spring:nestedPath path="orders">
    		<table width="90%" align="center">
    			<tr>
    				<td>Orders Id</td>
    				<td>
    					<c:out value="${orders.ordersId}"/>
    					<spring:bind path="ordersId">
    						<input type="hidden" name="ordersId" value="<c:out value="${orders.ordersId}"/>"/>
    					</spring:bind>
    				</td>
    			</tr>
    			<tr>
    				<td>Status</td>
    				<td>
    					<spring:bind path="status">
    						<input type="text" name="status" value="<c:out value="${orders.status}"/>"/>
    					</spring:bind>
    				</td>
    			</tr>
    			<c:forEach var="od" items="${orders.ordersDetails}" varStatus="loopStatus">
    				<spring:bind path="ordersDetails[${loopStatus.index}].itemId">
    					<input type="text" name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>"/>
    				</spring:bind>
    			</c:forEach>
    	</table>
    	</spring:nestedPath>
    </form>
    I manage to show the form with correct values. But when I submit the form, before arriving onSubmit, "Data binding errors: 1" was shown in log and the system jumped back to the form.

    If I tried commenting out the ordersDetails part, the form is submittable.

    I've tried adding the <spring:hasBindErrors> and activating log4j.logger.org.springframework=DEBUG, myLog. Both show nothing.

    How could I debug it?
    and is it appropriate to try maintaining a 1-N relations in this way?

  • #2
    Is there actually a non-null object inside orders.getOrdersDetails().get(0) ? The objects inside your collection can't be null (although the properties on the objects inside the collection can be null).

    Comment


    • #3
      I've init all the collections inside, and the form could be displayed with correct Orders and OrdersDetail values.

      I got the binding error when I tried submitting the form.

      I'm wondering is there special handling to instantiate a form object with collection inside...

      Comment


      • #4
        Originally posted by Kei
        I'm wondering is there special handling to instantiate a form object with collection inside...
        Not really. Are you using a session form? Are you using Hibernate? Where do you load the object (inside formBackingObject()?)

        It might help to post your controller code, including the XML bean definition for it.

        Comment


        • #5
          Oh ...

          You are right. I should use a session form.

          Once I add the setSessionForm(true) into the controller constructor, it works fine now.

          Thx a lot.

          Comment

          Working...
          X