English 中文(简体)
MVC泉水田
原标题:Hidden field in spring MVC

我想在以下法典中使用春天会隐藏的标签。 在以下法典中,这样做是可能的,我不得不在我的控制者中写一下,才能这样做,或者我正在做些什么是正确的。

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

任何帮助都将受到高度评价。

最佳回答

您正处在正确轨道上[取决于您的背信条],但为了将身份识别作为隐蔽的领域(on submission<>>/em>自动地“Person” bean(就这个例子而言),你将做以下事情:

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

请参看render。 a 隐蔽领域,您将使用form:hiddentag:

<form:hidden path="id" />

查阅 隐蔽 Input Tag of the Spring docs.

问题回答

在答复的其余部分,用你试图执行的行动取代“支离破碎”和“欺骗”。 例如,“被开发”、“借用”或“被遗弃”

阁下颁布的《共同财产法》有几个问题。

  1. no close tag for the <td> element.
  2. your form is posting to "items.html". This seems to be an html page. If so, your form action is 0% correct.
  3. every form has the same id, so the getElementById() call can never work.
  4. href="#" will cause your page to scroll to the top when the user clicks the link.
  5. You do not identify, to the user, the record to be deleted.

这里我想的是:

<c:forEach var="record" items="${records}">
    <tr>
        <td>
            <form:form method="post">
                <input type="hidden" name="activity" value="delete"/>
                <input type="hidden" name="record" value="${record}"/>
                <a href="javascript:this.form.submit()">Delete ${record}</a>
            </form:form>
        <td>
    </tr>
</c:forEach>

狙击手将派到目前的春季控制员。 该员额包括两个领域:“活动”,其中将“活动”确定为删除和“记录”,确定应予删除的记录。 根据您的需要,在<代码>格式:form tag上添加<编码>=“某些 url”。

我认为,我解决了这一问题。 如果我写上这样的投入标记的话。

<form:hidden path="id" value="${record}" />

这样,我就可以重新分配隐蔽变量的价值,但当我看一看已经颁布的《html法典》时,我就这样认为。

<input type="hidden" value="0" name="record" value="10"/>

产生价值两次,得出我所希望的价值10。 但它解决了我的问题。 如果任何人对此有进一步的评论,将不胜感激。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签