如何将表中的行发送到struts动作?

时间:2013-02-17 11:08:58

标签: forms struts2

我使用struts迭代器标记显示了一个表。现在每一行都有一个编辑链接。单击编辑按钮时,我需要能够将该行发送到操作中。

但我无法理解如何做到这一点。我有

<s:form action="/execute" id="frm" name="frm" method="POST">
    <table style="width: 800px; ">
        <thead>
            <tr>
                <th>ID</th>
                <th>Name</th>        
                <th>Actions </th>      
            </tr>
        </thead>
        <s:iterator value="listToIterate" var="row" status="stat" begin="0" >
            <tbody>    

                <tr>    
                    <td><s:property value="ID"  /></td>
                    <td><s:property value="Name"  /></td>               
                    <td><s:a href="#" onclick="document.forms['frm'].submit();">
                            edit<s:param name="Name" value="%{#row[2]}"/></s:a></td>        
                    </tr>       
                </tbody>    
        </s:iterator>
    </table>
</s:form> 

使用param标签我想将行设置为参数,以便我可以在我的操作中检索它。我该怎么做?

1 个答案:

答案 0 :(得分:1)

假设你的表单正确显示了id ...然后用你的s:a代替这个表单:

<s:a namespace="/yournamespace" action="the-edit-action">
   edit<s:param name="ID" value="ID"/>
</s:a>

我宁愿将ID称为id。 -edit-action需要一个id的getter和setter。