If you want to do a redirect, you need your action mapping to handle "cancel" and use a redirectAction result.
On Tue, Oct 15, 2013 at 12:53 PM, Antonio Sánchez <juntandolin...@gmail.com>wrote: > Hi. > > Simple CRUD sample application, paramsPrepareParams, wildcard method > selection. > > Cancel button in edit form, when reached for creating a new employee bean, > is not cancelling and redirecting to index, but actually performing form > action, which is "save". Conversely, cancel is working properly if edit > form is reached from "edit" link, instead of "create". > > I guess it has to do with interceptors stacks and validation, but I have > no idea where the problem is. > > Code for cancel button in employeeForm.jsp: > > <s:submit value="%{getText('button.**label.cancel')}" > name="redirectAction:index"/> > > Working on issue: > https://issues.apache.org/**jira/browse/WW-3993<https://issues.apache.org/jira/browse/WW-3993> > > Thanks! > > - struts.xml: > > <package name="default" namespace="/" extends="struts-default"> > > <default-action-ref name="index"/> > > <action name="index" class="struts.apache.org.**simpleCRUD.action. > **EmployeeAction" method="list"> > <result name="success">/WEB-INF/jsp/**employees.jsp</result> > <interceptor-ref name="basicStack"/> > </action> > <action name="*Employee" class="struts.apache.org.** > simpleCRUD.action.**EmployeeAction" method="{1}"> > <result name="success" type="redirectAction">index</**result> > <result name="input">/WEB-INF/jsp/**employeeForm.jsp</result> > <result name="error">/WEB-INF/jsp/**error.jsp</result> > <interceptor-ref name="**paramsPrepareParamsStack"/> > </action> > </package> > > - EmployeeAction > > public class EmployeeAction extends ActionSupport implements Preparable { > private EmployeeService empService = new EmployeeDaoService(); > private DepartmentService deptService = new DepartmentDaoService(); > > private Employee employee; > private List employees; > private List departments; > > public void prepare() throws Exception { > departments = deptService.getAllDepartments(**); > > if (employee != null > && employee.getEmployeeId() != null > && !("".equals(employee.**getEmployeeId())) ) { > employee = empService.getEmployee(**employee.getEmployeeId()); > } > } > > public String save() { > if (employee.getEmployeeId() == null) { > empService.insertEmployee(**employee); > } else { > empService.updateEmployee(**employee); > } > return SUCCESS; > } > > public String delete() { > empService.deleteEmployee(**employee.getEmployeeId()); > return SUCCESS; > } > > public String list() { > employees = empService.getAllEmployees(); > return SUCCESS; > } > > ................. > > - employees.jsp (index): > > <h1><s:text name="label.employees"/></h1> > <s:url id="url" action="inputEmployee" /> > <a href="<s:property value="#url"/>">Add New Employee</a> > > ....... > > <s:iterator value="employees" status="status"> > <tr class="<s:if test="#status.even">even</s:** > if><s:else>odd</s:else>"> > <td class="nowrap"><s:property value="firstName"/></td> > <td class="nowrap"><s:property value="lastName"/></td> > <td class="nowrap"><s:property value="age"/></td> > <td class="nowrap"><s:property value="department.name"/></td> > <td class="nowrap"> > <s:url action="inputEmployee" id="url"> > <s:param name="employee.employeeId" > value="employeeId"/> > </s:url> > <a href="<s:property value="#url"/>">Edit</a> > > <s:url action="deleteEmployee" id="url"> > <s:param name="employee.employeeId" > value="employeeId"/> > </s:url> > <a href="<s:property value="#url"/>">Delete</a> > </td> > </tr> > </s:iterator> > > - employeeForm (reached from add and edit employee links): > > <s:form action="saveEmployee" method="post"> > <s:textfield name="employee.firstName" value="%{employee.firstName}" > label="%{getText('label.**firstName')}" size="40"/> > <s:textfield name="employee.lastName" value="%{employee.lastName}" > label="%{getText('label.**lastName')}" size="40"/> > <s:textfield name="employee.age" value="%{employee.age}" > label="%{getText('label.age')}**" size="20"/> > <s:select name="employee.department.**departmentId" > value="%{employee.department.**departmentId}" list="departments" > listKey="departmentId" listValue="name"/> > <s:hidden name="employee.employeeId" value="%{employee.employeeId}"** > /> > <s:submit value="%{getText('button.**label.submit')}"/> > <s:submit value="%{getText('button.**label.cancel')}" > name="redirectAction:index"/> > </s:form> > > > > > > > > > > ------------------------------**------------------------------**--------- > To unsubscribe, e-mail: > user-unsubscribe@struts.**apache.org<user-unsubscr...@struts.apache.org> > For additional commands, e-mail: user-h...@struts.apache.org > > -- Cheers, Paul