从JSP到Java Action类

时间:2016-06-16 16:58:21

标签: jsp struts2 crud

我能够在JSP页面上打印列表User。每行都是一个对象EDIT。我在DELETE<s:iterator value="displayList" var="eachUser" > <tr> <td> <s:property value="#eachUser.EmailId"/> </td> <td> <s:property value="#eachUser.PasswordKey"/> </td> <td> <a href="PresentRegisterScreen"> Edit </a> </td> <td> <a href="DeleteUser"> Delete </a> </td> </tr> </s:iterator> 的每一行末尾都有一个链接相同的对象。

All Registered Users - Admin View
Email Id    Password    Edit    Delete
Paul    tata    Edit    Delete
Samy    tata1$  Edit    Delete
DaLin   tiger1$ Edit    Delete
Joshua  lion1$  Edit    Delete

屏幕上的输出如下所示

所有记录:

Paul

如何将所选对象传递给Action类?或者,如果用户点击了<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/ssoViewerLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <WebView android:id="@+id/ssoViewer" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="0"/> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="match_parent" android:orientation="horizontal" android:layout_height="0dip" android:layout_weight="1" android:gravity="center|bottom"> <Button android:id="@+id/cancelSSO" android:layout_marginTop="16dp" android:layout_width="125dp" android:layout_height="55dp" android:layout_margin="5dp" android:onClick="cancelSSOClick" android:text="Cancel Login" android:background="@drawable/button_login" /> <Button android:id="@+id/resetSSO" android:layout_marginTop="16dp" android:layout_width="125dp" android:layout_height="55dp" android:layout_margin="5dp" android:onClick="resetSSOClick" android:text="Reset SSO" android:background="@drawable/button_login"/> </LinearLayout> </LinearLayout> 的修改链接,或者如何在我的操作类中获取该对象。

1 个答案:

答案 0 :(得分:1)

  

当有人点击编辑(或)删除时,如何知道用户选择了哪一行,以便我可以在下一个操作类/屏幕中为编辑/删除获取特定的对象/行值。

这很简单,您只需修改链接以包含带有对象ID的参数,例如emailId

<td> <s:a action="PresentRegisterScreen"><s:param name="emailId" value="%{emailId}"/> Edit  </s:a> </td>
<td> <s:a action="DeleteUser"><s:param name="emailId" value="%{emailId}"/> Delete  </s:a> </td>

您还使用getter和setter为action bean创建了一个属性emailId。现在,如果单击链接,操作将调用并将参数设置为操作。您将获得该属性的值,并找到您想要“编辑(或)删除”的emailId对象。