Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...