Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

struts 2 multiple delete buttons pass value to action

 
Soheil Arian
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 213
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic