如何使用Struts2为JSP页面使用多个按钮(每行一个) [英] How to use multiple buttons (one on each line) for JSP page using Struts2

查看:124
本文介绍了如何使用Struts2为JSP页面使用多个按钮(每行一个)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的不知道如何标题我的问题,但我有一个JSP页面,其中有一个表格显示数据库中的元素,我希望每行都有一个按钮来删除或编辑该特定行。这是我生成表格的JSP页面的一部分(表和按钮生成正常)

I don't really know how to title my question, but I have a JSP page with a table displaying elements from a database, and I want to have a button for each row to either delete or edit that particular row. Here is the part of my JSP page where I generate the table (the table and buttons are generated fine)

<style type="text/css">
  table { empty-cells: show; }
</style>
<table border="1">
<tr>
<th>Action</th>
  <s:iterator value="columnNames" id="name">
    <th> <s:property value="name" /> </th>
  </s:iterator>
</tr>
 <s:iterator value="%{table}" id="row">
 <tr>
   <td>
   <table><tr><td>
   <s:form action="edit" namespace="/." theme="simple">
   <s:submit value="Edit" name="edit" />
   </s:form></td>
   <td>
   <s:form action="remove" namespace="/." theme="simple">
   <s:submit value="Remove" name="remove" />
   </s:form></td></tr>
   </table></td>
     <s:iterator value="%{#row}" id="cell">
          <td><s:property value="%{#cell}"/></td>
     </s:iterator>
 </tr>
 </s:iterator>
</table>

我如何获得它,以便当我点击某一行上的特定按钮时,我的程序将知道它应该执行哪一行(编辑/删除)?对不起,我仍然是Struts2的新手......

How would I get it so that when I click on a particular button on a certain row, that my program will know which row it should perform the action on (edit/delete)? Sorry, I'm still pretty new to Struts2 still...

推荐答案

我不知道为什么你有一个嵌套的表只是按钮......也许是布局。我建议让你的每个顶级都有一个表单,其中包含另一个标识行的属性,以及两个提交按钮。

I'm not sure why you have a table nested for just the buttons... perhaps it's for layout. I would suggest making each of your top-level have a form with another attribute identifying the row, and two submit buttons.

例如。这样的事情(未经测试)

e.g. something like this (untested)

<s:form theme="simple">
    <s:hidden key="rowID" />
    <s:submit action="remove" value="Remove"/>
    <s:submit action="edit" value="Edit"/>
</s:form>

您可以拥有一个单独的表单,每个表单都有多个操作。只需在行中添加一些唯一标识您将要操作的行的内容。

You can have a single form with multiple actions for each. Just put something in the row that uniquely identifies the row that you'll be acting upon.

那么,当提交此内容时,会发生什么,rowID将包含在请求中并作为参数发送到您的特定操作到setter(setRowID())。只需从原始数据中选择一些唯一标识它的东西。

So, what'll happen is that when this is submitted, the rowID will be included in the request and sent to your specific action as a parameter to the setter (setRowID()). Just pick something from whatever your original data is that uniquely identifies it.

这篇关于如何使用Struts2为JSP页面使用多个按钮(每行一个)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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