How to get result on same page why input is required?

后端 未结 2 1952
面向向阳花
面向向阳花 2020-12-03 09:37

In my project I am updating details so I created action, but it gives me exception in response as

No result defined for action org.employee.actions.EmployeeM         


        
相关标签:
2条回答
  • 2020-12-03 09:54

    Not everything is correct as you thought, because in the success callback function you have received INPUT result. This result is returned by workflow interceptor, which is in the defaultStack - the stack of interceptors used by default if your action doesn't override the interceptors configuration. It checks if an action invocation has validation errors like action errors or field errors (the conversion errors) then returns a result specified by the parameter inputResultName. By default this parameter is set to "input". If the interceptor returns a result it breaks a chain of interceptors and invocation of action method. You noted it saying It is not going to the action class declared.

    The solution is to override interceptors configuration of the action to use basic stack, i.e. without validation and/or workflow interceptors.

    <action name="savePersonalDetails"  class="org.employee.actions.EmployeeMyProfileAction" method="updateEmployeeDetails">
      <interceptor-ref name="basicStack"/>
      <result name="success">empMyProfile.jsp</result>
    </action>
    

    If you still need to perform validations you can do it programmatically or configure workflow interceptor to filter your action method. The last option you should use only if you have enough reasons to do so, because it overcomes the purpose of the interceptor itself.

    0 讨论(0)
  • 2020-12-03 10:07

    Assumning you know what the INPUT result is and how it works, you are doing the wrong thing here.

    When you perform an AJAX call, 1) the result will be parsed (and then eventually injected) in your current page, or, alternatively, you can use that result to perform a redirect by using javascript (window.location = "newUrl";).

    You can't return a whole page and then use that response to make a new page (unless inside an iframe or similar, but that's DOM / page manipulation, then case 1).

    Then this

    <action name="savePersonalDetails" class="org.employee.actions.EmployeeMyProfileAction" method="updateEmployeeDetails">
        <result name="success">empMyProfile.jsp</result>
        <result name="input">emp-personal-form.jsp</result>
    </action>
    

    can't be right, because both the result should be an entire page (in case of a classic POST) or a JSP snippet / JSON / whatever (in case of an AJAX CALL).

    You should change it to something like

    <action name="savePersonalDetails" class="org.employee.actions.EmployeeMyProfileAction" method="updateEmployeeDetails">
        <result name="success">emp-personal-form.jsp</result>
        <result name="input">emp-personal-form.jsp</result>
        <result name="error">emp-personal-form.jsp</result>
    </action>
    

    and include in the first rows of emp-personal-form.jsp a message with the errors (in case of INPUT or ERROR results), or a message of success (in case of SUCCESS result) and then provide a link to navigate away from the page.

    Otherwise, use standard POST and return the same page in case of INPUT or ERROR, or a success page in case of SUCCESS:

    <action name="savePersonalDetails" class="org.employee.actions.EmployeeMyProfileAction" method="updateEmployeeDetails">
        <result name="success">profileCorrectlyUpdated.jsp</result>
        <result name="input">empMyProfile.jsp</result>
        <result name="error">empMyProfile.jsp</result>
    </action>
    

    But nothing prevent you to use standard POST and return in the same page also in case of SUCCESS.

    Note: to know how display a (success or error) message only when needed, read this.

    0 讨论(0)
提交回复
热议问题