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.
Thanks
I think I solved the problem. If I write input tag like this
in this way I can reassign the value of hidden variable but when I look into the rendered html code its like this
generate the value attribute twice and takes the value I wanted which is 10.But it solves my problem. If anyone has further comments on this then that will be appreciated.
In the rest of this answer, substitute "delete" and "deteted" with the operation you are attempting to implement. for example "exploded", "bitten", or "edited"
The JSP code you posted has several issues.
<td>
element.getElementById()
call can never work.href="#"
will cause your page to scroll to the top when the user clicks the link.Here is what I think you want:
The snippet will post to the current spring controller. Two fields are included in the post: "activity" which identifies this as a delete and "record" which identifies the record to be deleted. Based on your needs, add
action="some url"
to theform:form
tag.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:
In case you'd like to render a hidden field, you would use a
form:hidden
tag:Take a look at Hidden Input Tag section of the Spring docs.