You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Antonio Sánchez <ju...@gmail.com> on 2013/10/15 19:53:51 UTC

"Cancel" button is not redirecting

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

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>
                 &nbsp;&nbsp;&nbsp;
                 <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
For additional commands, e-mail: user-help@struts.apache.org


Re: "Cancel" button is not redirecting

Posted by Antonio Sánchez <ju...@gmail.com>.
Thanks!

El 16/10/2013 07:37 a.m., Lukasz Lenart escribió:
> Yes, I have downgraded to 2.3.15.1 and it will be fixed in 2.3.15.3
>
> 2013/10/16 Antonio Sánchez <ju...@gmail.com>:
>> So, is it still possible to render a cancel button in 2.3.15.2? Or must
>> downgrade to 2.3.15.1? Will the bug be fixed in 15.3?
>>
>> El Miércoles, 16 de Octubre de 2013 02:35:06 a.m., Lukasz Lenart escribió:
>>> 2013/10/15 Antonio Sánchez <ju...@gmail.com>:
>>>> Set to false.
>>>>
>>>> But having same results set to true.
>>>>
>>>> I'm using action="index" approach. Now, cancel always launches 404.
>>>
>>> It was related to bug in 2.3.15.2, now with 2.3.15.1 works fine!
>>>
>>>
>>> Regards
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: "Cancel" button is not redirecting

Posted by Lukasz Lenart <lu...@apache.org>.
Yes, I have downgraded to 2.3.15.1 and it will be fixed in 2.3.15.3

2013/10/16 Antonio Sánchez <ju...@gmail.com>:
> So, is it still possible to render a cancel button in 2.3.15.2? Or must
> downgrade to 2.3.15.1? Will the bug be fixed in 15.3?
>
> El Miércoles, 16 de Octubre de 2013 02:35:06 a.m., Lukasz Lenart escribió:
>>
>> 2013/10/15 Antonio Sánchez <ju...@gmail.com>:
>>>
>>> Set to false.
>>>
>>> But having same results set to true.
>>>
>>> I'm using action="index" approach. Now, cancel always launches 404.
>>
>>
>> It was related to bug in 2.3.15.2, now with 2.3.15.1 works fine!
>>
>>
>> Regards
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: "Cancel" button is not redirecting

Posted by Antonio Sánchez <ju...@gmail.com>.
So, is it still possible to render a cancel button in 2.3.15.2? Or must 
downgrade to 2.3.15.1? Will the bug be fixed in 15.3?

El Miércoles, 16 de Octubre de 2013 02:35:06 a.m., Lukasz Lenart 
escribió:
> 2013/10/15 Antonio Sánchez <ju...@gmail.com>:
>> Set to false.
>>
>> But having same results set to true.
>>
>> I'm using action="index" approach. Now, cancel always launches 404.
>
> It was related to bug in 2.3.15.2, now with 2.3.15.1 works fine!
>
>
> Regards



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: "Cancel" button is not redirecting

Posted by Lukasz Lenart <lu...@apache.org>.
2013/10/15 Antonio Sánchez <ju...@gmail.com>:
> Set to false.
>
> But having same results set to true.
>
> I'm using action="index" approach. Now, cancel always launches 404.

It was related to bug in 2.3.15.2, now with 2.3.15.1 works fine!


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: "Cancel" button is not redirecting

Posted by Antonio Sánchez <ju...@gmail.com>.
Set to false.

But having same results set to true.

I'm using action="index" approach. Now, cancel always launches 404.




El Martes, 15 de Octubre de 2013 12:59:32 p.m., Paul Benedict escribió:
> 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
> <ju...@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>
>>                  &nbsp;&nbsp;&nbsp;
>>                  <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<us...@struts.apache.org>
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: "Cancel" button is not redirecting

Posted by Lukasz Lenart <lu...@apache.org>.
is DMI set to true?

2013/10/15 Antonio Sánchez <ju...@gmail.com>:
> Support for redirectAction: and redirect: prefixes was removed as from
> version 2.3.15.1. So, let's forget redirection this way.
>
> I was using redirection because using
>
> <s:submit value="%{getText('button.label.cancel')}" action="index"/> (the
> same than name="action:index"?)
>
> throws error 404, resource not available: "myapp/index.action".
>
> Using method does not work either:
>
> <s:submit value="%{getText('button.label.cancel')}" method="cancel"/>
>
>     public String cancel() {
>         return "cancel";
>     }
>
> <result name="cancel" type="redirectAction">index</result>
>
> I'm not sure if Paul was meaning this.
>
>
> El 15/10/2013 12:59 p.m., Paul Benedict escribió:
>>
>> 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
>> <ju...@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>
>>>                  &nbsp;&nbsp;&nbsp;
>>>                  <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<us...@struts.apache.org>
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: "Cancel" button is not redirecting

Posted by Antonio Sánchez <ju...@gmail.com>.
Support for redirectAction: and redirect: prefixes was removed as from 
version 2.3.15.1. So, let's forget redirection this way.

I was using redirection because using

<s:submit value="%{getText('button.label.cancel')}" action="index"/> (the same than name="action:index"?)

throws error 404, resource not available: "myapp/index.action".

Using method does not work either:

<s:submit value="%{getText('button.label.cancel')}" method="cancel"/>

     public String cancel() {
         return "cancel";
     }

<result name="cancel" type="redirectAction">index</result>

I'm not sure if Paul was meaning this.


El 15/10/2013 12:59 p.m., Paul Benedict escribió:
> 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
> <ju...@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>
>>                  &nbsp;&nbsp;&nbsp;
>>                  <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<us...@struts.apache.org>
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: "Cancel" button is not redirecting

Posted by Paul Benedict <pb...@apache.org>.
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
<ju...@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>
>                 &nbsp;&nbsp;&nbsp;
>                 <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<us...@struts.apache.org>
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
Cheers,
Paul