使用显示标记从 JSP 页面中的行获取值
抱歉,有一堆 Struts2 / JSP 问题,但我有一个使用 显示标记 生成的表:
<display:table name="table" pagesize="10" id="row" requestURI="">
<display:column title="Action">
<s:form theme="simple">
<s:submit action="remove" value="Remove"
onclick="return confirm('Are you sure you want to delete this item?');"/>
<s:submit action="displayEdit" value="Edit"/>
</s:form>
</display:column>
<display:column property="cpc" title="CPC"/>
<display:column property="companyName" title="Company Name"/>
<display:column property="eventType" title="Event Type"/>
<display:column property="industryType" title="Industry Type"/>
<display:column property="previousEvents" />
<display:column property="creditNotifications" />
<display:column property="interimNotifyEnterprise" />
</display:table>
现在我希望能够删除或编辑某一行(我已经写出了操作),但是如何获取每行的特定数据,以便我可以告诉我的 Action 类要编辑或删除哪一行?
Sorry for a bunch of Struts2 / JSP questions, but I have a table generated with Display tag:
<display:table name="table" pagesize="10" id="row" requestURI="">
<display:column title="Action">
<s:form theme="simple">
<s:submit action="remove" value="Remove"
onclick="return confirm('Are you sure you want to delete this item?');"/>
<s:submit action="displayEdit" value="Edit"/>
</s:form>
</display:column>
<display:column property="cpc" title="CPC"/>
<display:column property="companyName" title="Company Name"/>
<display:column property="eventType" title="Event Type"/>
<display:column property="industryType" title="Industry Type"/>
<display:column property="previousEvents" />
<display:column property="creditNotifications" />
<display:column property="interimNotifyEnterprise" />
</display:table>
Now I want to be able to delete or edit a certain row (I already have the actions written out), but how would I get the specific data for each row so I can tell my Action class which row to edit or delete?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在之前的 你前几天问过的问题。您只需要行中的某些内容(可能是隐藏字段)即可用于唯一标识该项目。
我建议在行中使用
,它将随操作一起提交。只要您的对象上有类似的属性,并且在删除操作中,您有一个 setter 来接收该值,您就可以使用它来唯一标识该行。I mentioned this in the previous question you asked the other day. You just need to something in your row, possibly a hidden field, that can be used to uniquely identify the item.
I suggested using an
<s:hidden key="rowID" />
in the row, which would get submitted with the action. As long as you had a property like that on your object, and in the remove action, you had a setter to receive that value, you could use that to uniquely identify the row.您的表似乎在每行对象类中没有唯一标识符字段。
您可以在要显示的 bean 类中添加 field -id 。 (Company bean 类中的companyId)。这样表中的每一行都将显示唯一的“公司”对象,并且根据“companyId”字段,您可以通过将“companyId”传递给 Action 类来编辑/删除选定的对象。
您可能不喜欢在 UI 布局中向最终用户显示“companyId”列。在这种情况下,您可以使用“companyId”作为参数创建“编辑”和“删除”列的超链接。
有关更多详细信息,请参阅此网站上的 displaytag 教程。
It seems that your table does not have unique identifier field in class Object per Row.
You can add field -id in you bean-class that you are going to display. (companyId in Company bean class). So that every row in the table will display unique 'company' object and depending upon 'companyId' field you may edit/delete selected object by passing 'companyId' to Action class.
You may no like to display 'companyId' column in your UI layout to end-user. In that case you can just create hyperlink of 'edit' and 'delete' column using 'companyId' as parameter.
See displaytag tutorial at this site for more detail.
使用下面的方法来获取行 ID。
例如,我使用了单选按钮,
现在您可以使用
req.getParameter
轻松获取 rowNr 的值,并基于此您可以从您提供给显示标签表的列表中获取记录。use below to get row id.
eg i used radio button,
now u can easily get the value of rowNr using
req.getParameter
and based on this u can get the record from the list which u have supplied to display tag table.