弹出窗体从显示的对象列表中进行选择

时间:2013-10-24 03:35:41

标签: java spring spring-mvc

我正在以弹簧形式显示对象列表,如下所示

    <form:form method="POST"  commandName="productlist">
    <table>
    <c:forEach var="product" items="${productlist}">
    <tr id=${product.id}><td>${product.name}</td>  
    </tr>    
   </c:forEach>
   </table>
   </form:form>

现在,我希望在jsp中每个产品前面都有一个复选框,以便用户可以选择任何产品和选定的产品列表进入控制器进行进一步处理。提前谢谢。

2 个答案:

答案 0 :(得分:0)

在td

中添加一个复选框
<form:form method="POST"  commandName="productlist">
    <table>
    <c:forEach var="product" items="${productlist}">
    <tr id=${product.id}><td><form:checkbox path=""/>${product.name}</td>  
    </tr>    
   </c:forEach>
   </table>
   </form:form>

请参阅here

答案 1 :(得分:0)

您可以将表单支持对象定义为:

public class ProductForm {
private List<String> productList;//checkbox values to be shown
private String[] selProductList;//selected checkbox values available for processing
//other properties
...
//getters and setters
}

现在您可以将checkbox定义为:

<form:form action="/productAction" method="post" modelAttribute="productform">
<form:checkboxes items="${productform.productList}" path="selProductList" />
...
</form>

提交此form后,您可以通过selProductList数组使用所选的复选框值。