hi guys,
i was using the example crud application (
http://struts.apache.org/2.0.14/docs/crud-demo-i.html) as the skeleton for a
CRUD like module in my site.
But I've ran into a dead end.
in this sample applications the package is like this:
<package name="default" extends="struts-default">
<!-- Default interceptor stack. -->
<default-interceptor-ref name="paramsPrepareParamsStack"/>
<action name="index"
class="com.aurifa.struts2.tutorial.action.EmployeeAction"
method="list">
<result name="success">/WEB-INF/jsp/employees.jsp</result>
<!-- we don't need the full stack here -->
<interceptor-ref name="basicStack"/>
</action>
<action name="crud"
class="com.aurifa.struts2.tutorial.action.EmployeeAction"
method="input">
<result name="success" type="redirect-action">index</result>
<result name="input">/WEB-INF/jsp/employeeForm.jsp</result>
<result name="error">/WEB-INF/jsp/error.jsp</result>
</action>
</package
as you can see, they are directly calling the methods.
What I wanted to do was that when user edits something and comes back to the
listing page, they see a message on top saying id XXX has been modified.
However, I think this is not possible because a method name is mentioned in
struts.xml. Is that correct?
to try it out I added a private member string called successString in
EmployeeAction class and created getter/setters for it. Then in doSave and
doDelete methods I added a line that sets the member string. Then on the
listing jsp page. I simple added this line <s:property value="successString"
default="test"/> However, it seems that the jsp page is never getting the
value from getSuccessString method.
Can someone please tell me an approach I can take to overcome this problem?
Below are the doSave and doDelete methods.
public String doDelete() {
empService.deleteEmployee(employee.getEmployeeId());
setSampleString("successfully deleted");
return SUCCESS;
}
public String doSave() {
if (employee.getEmployeeId() == null) {
empService.insertEmployee(employee);
} else {
empService.updateEmployee(employee);
}
setSampleString("successfully edited");
return SUCCESS;
}