1

A project was passed onto me a short while ago which uses JSP for the view and spring 3.1 for the controller - both of which I have little experience in and as per usual, there are about 4 comments in the whole thing. Anyway, my issue is this, in replacing a

<form:checkboxes path="class.list" items="${items}" delimiter="<br />" />

With

<c:forEach var="item" varStatus="vs" items="${items}">
    <form:checkbox path="class.list" item="${item}" />
    // check if nesting is required, if so create div and nested list point to class.list.children
</c:forEach>

Seems to create additional elements in my class.list which are not selected leading to a break further on.

Any guidance would be greatly appreciated.

4

1 回答 1

1

我建议保留 form:checkboxes 完整,因为它是生成复选框的紧凑方式。如果弹簧表格标签已经到位并且可以工作,我不知道有什么令人信服的理由不使用它。至于为什么您会看到隐藏字段。见这里: http ://static.springsource.org/spring/docs/2.5.x/reference/view.html

以下是相关部分:您可能不会看到每个复选框后的附加隐藏字段。当 HTML 页面中的复选框未选中时,一旦提交表单,其值将不会作为 HTTP 请求参数的一部分发送到服务器,因此我们需要针对 HTML 中的这种怪癖的解决方法,以便进行 Spring 表单数据绑定去工作。复选框标记遵循现有的 Spring 约定,即为每个复选框包含一个以下划线 ("_") 为前缀的隐藏参数。通过这样做,您实际上是在告诉 Spring“复选框在表单中是可见的,并且我希望表单数据绑定到的对象无论如何都反映复选框的状态”。

希望这可以帮助。

于 2012-07-16T04:22:28.757 回答