如何编辑表格的字段? [英] How to edit fields of a table?

查看:84
本文介绍了如何编辑表格的字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格来显示一长列项目,我想知道如何编辑字段并提交表单以更新它们?

I have a table to show a long list of items, I am wondering how I can edit the fields and submit the form to update them?

 <form name="edit" method="POST" action="edit">
    <table border="4">
        <tbody>
            <c:forEach items="${basket.items}" var="item">
                <tr>
                    <td>
                        <input name="item.id" value="${item.id}"/>  
                    </td>
                    <td>
                        <input label="Price" value="${item.product.price}"/>
                        <br/>
                    </td>
                </tr>
            </c:forEach>
        </tbody>
    </table> 
    this is a new one
   <input id="edit" type="submit" name="edit" value="Edit"/>
</form>

推荐答案

您正在使用带有JSTL和EL而不是Struts标签和OGNL的Struts2 ...是否有特定的原因迫使您放弃大多数框架机制?

You are using Struts2, with JSTL and EL instead of Struts Tags and OGNL... is there a particular reason that forces you to drop most of the framework mechanics ?

也就是说,您的输入无效(未指定类型),HTML中的这是一个新的"句子似乎表明愿意插入新行,而不是编辑现有条目.您的描述和代码似乎在询问两种不同的事物:插入一个新的事物,只需调用该动作(或另一个动作)的另一种方法,称为添加",而不是编辑",发送一个元素并将其添加到集合中.无需在这里使用AJAX ...

That said, your inputs aren't valid (no type specified) and the "this is a new one" sentence in the HTML seems to indicate the willing to insert a new row, instead of editing the existing entres. Your description and your code seem to ask two different things... to insert a new one, just make a call to another method of the action (or another action) called "add" instead of "edit", sending one single element and adding it to the collection. No need to use AJAX here...

如果相反,问题实际上是:

If instead, the question is really:

我如何编辑字段并提交表单以更新它们?

how I can edit the fields and submit the form to update them ?

这是方法:

<s:form method="POST" action="edit">
    <table border="4">
        <tbody>
            <s:iterator value="basket.items" var="item" status="ctr">
                <tr>
                    <td>
                        <s:textfield name="item[%{#ctr.index}].id" />
                    </td>
                    <td>
                        <s:textfield name="item[%{#ctr.index}].product.price" />
                    </td>
                </tr>
            </s:iterator>
        </tbody>
    </table> 
    <s:submit value="Edit"/>
</form>

这篇关于如何编辑表格的字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆