Java – hidden fields in MVC

I want to use spring hidden tags in the following code Is it possible that in the following code, I have to write these in my controller, or what I'm 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 appreciated

thank you

Solution

You are on the right track [depending on what your supported bean is], but in order to bind the ID as a hidden field to the automatically submitted "person" bean (in this example), you will do the following:

<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>

If you want to render a hidden field, you will use a form: hidden tag:

<form:hidden path="id" />

Look at the hidden input tag section of the spring documentation

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>