春季MVC中的隐藏场 [英] Hidden field in spring MVC
本文介绍了春季MVC中的隐藏场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在下面的代码中使用spring hidden标签.在下面的代码中这是否可行,我必须在控制器中编写的内容还是我所做的都是正确的.
I wanted to use spring hidden tag in below code. Is this possible in below code, what I have to write in my controller to do that or what I am doing is correct.
<c:forEach var="record" items="${records}">
<tr>
<td>
<form:form id="myForm" action="list.html" method="post">
<input type="hidden" name="record" value="${record}" />
<a href="#" onclick="document.getElementById('myForm').submit();">Submit</a>
</form:form>
</td>
</tr>
</c:forEach>
任何帮助都会得到高度重视.
Any help will be highly appriciated.
谢谢
推荐答案
您处于正确的轨道上(取决于您的后备bean是什么),但是为了在提交时将ID绑定为隐藏字段 自动添加到"Person" bean(在此示例中),您将执行以下操作:
You are on the right track [depending on what your backing bean is], but in order to bind an ID as a hidden field on submission automatically to a "Person" bean (in this example), you would do something like:
<c:forEach var="person" items="${persons}" varStatus="status">
<tr>
<c:set var="personFormId" value="person${status.index}"/>
....
<form id="${personFormId}" action="${deleteUrl}" method="POST">
<input id="id" name="id" type="hidden" value="${person.id}"/>
</form>
<td>${person.firstName}</td>
<td>${person.lastName}</td>
....
</tr>
</c:forEach>
如果您想渲染一个隐藏字段,则可以使用form:hidden
标签:
In case you'd like to render a hidden field, you would use a form:hidden
tag:
<form:hidden path="id" />
看看隐藏的输入标记部分.
这篇关于春季MVC中的隐藏场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文