我在这里有一个Spring MVC应用程序。当打开菜单页面时,我将放置两个模型属性:menuList和orderList。 menuList填充了来自数据库的信息,orderList是空列表,我想在客户端提交动态表单时完全填充。我知道如何从订单列表中的菜单中绑定所有产品,但这会浪费很多东西。我需要做的是检查每个产品旁边动态附加的输入字段" pieces"的值或长度是否大于0.我该怎么做?
<c:url value="/menu/order" var="orderPath"/>
<form:form action="${orderPath}" method="POST" modelAttribute="orderList">
<table>
<tr>
<th>Name</th>
<th>Code</th>
<th>Price</th>
<th>Description</th>
<th>Calories</th>
<th>Image</th>
<th>Pieces</th>
</tr>
<c:set var="index" value="0" scope="page" />
<c:forEach items="${menuList}" var="menu" varStatus="i">
<tr>
<td>${menu.name}</td>
<td>${menu.code}</td>
<td>${menu.price}</td>
<td>${menu.description}</td>
<td>${menu.calories}</td>
<td><img src="<c:url value="/images/${menu.image}" />" alt="" width=120></td>
<td><input type="text" name="pieces"></td>
<!-- i need to take the "pieces" input field value here and check it if,
lets say, the length is greater than 0 (or the value is greater than 0)
and to make data binding only in those situations
I saw something like <c:if test="${param.pieces}>0"> but that's not working
or maybe i'm doing some kind of mistake, i don't know
-->
<!--start: this code should be executed if the condition is evaluated to true -->
<form:hidden path="orderList[${index}].orderID"/>
<form:hidden path="orderList[${index}].menuID" value="${menu.menuID}"/>
<form:hidden path="orderList[${index}].pieces" value="**value-of-pieces-input-field**"/>
<c:set var="index" value="${index + 1}" scope="page" />
<!--end -->
</tr>
</c:forEach>
<tr>
<td colspan="2">
<input type="submit" value="Make an order"/>
</td>
</tr>
</table>
</form:form>
答案 0 :(得分:1)
你很亲密。
<c:if test="${param.pieces > 0 }">
<form:hidden path=.../>
</c:if>