I have a problem with Struts 2.
- Retrieve necessary data from database.
- Show the data in JSP
- In the JSP, I will do submit the form.
- The retrieved data doesn't exist in the JSP page.
- To show, I need to retrieve the data from database again.
So, I need to retrieve the data from database in every submit action of the same page. But I don't want to retrieve like it. How can I maintain the data in submit action?
JSP Page:
<s:form name="XXXXXX" action="XXXXXXXX" method="post">
<div align="right" style="width: 80%">
<display:table name="userSearchForms" pagesize="${pageSize}"
cellpadding="5px;" cellspacing="5px;" requestURI=""
class="displayTable" id="displayTable"
style="border: 3px solid #D9D9D9; border-collapse: collapse; width: 100%;height: 100%;align: right;border: 3px solid #D9D9D9;">
<display:column title="#" style="border:1px solid black;">
<input type="radio" name="prep"
onclick="selectRadio(this.form, '<s:property value="#attr.displayTable.companyId"/>','<s:property value="#attr.displayTable.userId"/>')">
</display:column>
<display:column title="companyName" property="companyName" value="companyName"
style="border:1px solid black;"></display:column>
<display:column title="departmentName" property="departmentName" value="departmentName"
style="border:1px solid black;"></display:column>
<display:column title="userName" property="userName" value="userName"
style="border:1px solid black;"></display:column>
<display:column title="email" property="email" value="email"
style="border:1px solid black;"></display:column>
</display:table>
</div>
<div style="margin-left: 10%; width: 80%; text-align: right;">
<s:submit value="Register" action="OtherAction1"/>
<s:submit value="Update" action="OtherAction2" />
<s:submit value="Delete" action="OtherAction3"/>
</div>
</s:form>
Action Class:
public class sampleAction extends ActionSupport{
private List<searchForm> userSearchForms;
public List<searchForm> getUserSearchForms() {
if (userSearchForms == null) {
userSearchForms = new ArrayList<searchForm>();
}
return userSearchForms;
}
public void setUserSearchForms(List<searchForm> userSearchForms) {
this.userSearchForms = userSearchForms;
}
public String execute(){
// Retrieve the data from database;
// Set to the userSearchForms;
return SUCCESS;
}
public String OtherAction1(){
// Other Program Logic;
return SUCCESS;
}
public String OtherAction2(){
// Other Program Logic;
return SUCCESS;
}
public String OtherAction3(){
// Other Program Logic;
return SUCCESS;
}
}
I need to retrieve data from database in OtherAction1
, OtherAction2
and OtherAction3
method.