Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
178 views
in Technique[技术] by (71.8m points)

java - How to edit fields of a table?

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 ?

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 ?

this is the way:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...