GeeCON Prague 2014*
The moose likes Struts and the fly likes struts 2 multiple delete buttons pass value to action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts 2 multiple delete buttons pass value to action" Watch "struts 2 multiple delete buttons pass value to action" New topic
Author

struts 2 multiple delete buttons pass value to action

Soheil Arian
Greenhorn

Joined: Apr 04, 2013
Posts: 1
Hi,

I have struts 2 question that i cannot find the answer for. can someone please help.
I have a table dynamically return after pressing search. in front of each row a dynamically delete button is created. how can I associate each button to the record:
JSP:
<div>
<s:iterator value="users" status="index" >
<s:if test="#index.first == true">
<tr style="font-weight:bold; background: #2E2E2E ">
<td></td>
<td></td>
<td>User ID</td>
<td>First Name</td>
<td>Last Name</td>
<td>Email</td>
<td>Status</td>
<td>Type</td>
</tr>
</s:if>
<s:if test="#index.odd == true">
<tr style="background: grey">
</s:if>
<s:else>
<tr style="background: #0B243B ">
</s:else>
<td><s:submit type="image" src="images/icons/deleteButton.ico" theme="simple" method="delete" name="myUser" value="<s:property value='userID'/>" /></td>
<td><s:property value="userID"/></td>
<td><s:property value="firstName"/></td>
<td><s:property value="lastName"/></td>
<td><s:property value="email"/></td>
<td><s:property value="statusID"/></td>
<td><s:property value="typeID"/></td>
</tr>
</s:iterator>
</div>

Action:
public class userAdminAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private String myUser;

public String delete() throws Exception {
System.out.println("delete:");
System.out.println("My User is: " + myUser);
return "success";
}

public String getMyUser() {
return myUser;
}

public void setMyUser(String myUser) {
this.myUser = myUser;
}
}

OUTPUT:
delete:
My User is: null

Can someone please help........
Richard Golebiowski
Ranch Hand

Joined: May 05, 2010
Posts: 213

You need to return the ID value so IMHO you have two options. Replace the submit tag with an action tag or handle the click event on the submit tag to call the action and return the id value.
 
GeeCON Prague 2014
 
subject: struts 2 multiple delete buttons pass value to action