Reputation: 6399
There is a page in which there are multiple rows with a 'Change Status' button[a 'submit' button] at the end of each row. There are more than ten status present. When I click on the 'Change Status' button, the control goes the action class and the page reloads with the changed status.
I have id's associated with each row. how do I identify in which row I have clicked the 'Change Status' button when the page reloads ? Should I pass the id through java-script to the action class ? Is there a simpler way than this ?
Upvotes: 0
Views: 178
Reputation: 94
You can do a different form for each row. Every form can have a
<s:hidden />
with the id of the row. In this way you always know which is the submit clicked.
Upvotes: 0
Reputation: 23587
Well you can take advantage of Struts2 multiple submit button functionality.Like you can set submit button value based on your ID and collect that in your action to use it in your way something like
<button type="submit" value="Submit" name="buttonName">
<button type="submit" value="Clear" name="buttonName">
class MyAction extends ActionSupport {
private String buttonName;
public void setButtonName(String buttonName) {
this.buttonName = buttonName;
}
public String execute() {
if ("Submit".equals(buttonName)) {
doSubmit();
return "submitResult";
}
if ("Clear".equals(buttonName)) {
doClear();
return "clearResult";
}
return super.execute();
}
}
So in short value can be what is the uniqque id and you can use it in action as per your choice for details
Upvotes: 2
Reputation: 13272
You can add the id to be part of your form and that way you will receive the id as a parameter when you submit. No need for javascript.
Upvotes: 0