Struts2 addActionError setting result to input automatically on redirect result

為{幸葍}努か 提交于 2019-12-13 01:35:09

问题


I have a struts2 action, which sets some error using addActionError something like below

 public String del() {
        if (new OrdersService().get(idorder) == null) {
            addActionError("Order not found");
        } else {
            new OrdersService().remove(idorder);
            addActionMessage("Order deleted successfully");
        }
        return SUCCESS;
    }

So the above method NO MATTER WHAT always return "success" result.

But in struts.xml I've used the redirect result-type to redirect to another action and that action is never executed instead I'm getting result "input", I'm unable to understand what's going wrong ?

Is it something like If an action sets an actionError, another action can't be executed and straight away "input" result will be thrown. But it doesn't make sense (at least to me)!

[EDIT] including some part of struts.xml

<action name="/order/{idorder:[0-9]+}/del" class="actions.OrderAction" method="del">
    <interceptor-ref name="store">
        <param name="operationMode">AUTOMATIC</param>
    </interceptor-ref>
    <interceptor-ref name="defaultStack" />

    <result name="success" type="redirect">orders</result>
</action>

回答1:


The default stack includes the "workflow" interceptor.

If there are action or field errors this interceptor returns the "input" result, because there was an error.

Reading some documentation will point you in the right direction. Note that your errors will be lost on a redirect anyway, unless you specifically save them.

Also, if you want to redirect to an action, use the "actionRedirect" result type.




回答2:


public String del() {
    if (new OrdersService().get(idorder) == null) {
        addActionError("Order not found");
        return ERROR;
    } else {
        new OrdersService().remove(idorder);
        addActionMessage("Order deleted successfully");
        return SUCCESS;
    }
}

Also include return type 'error' as you have done for return type 'success' in your action mapping in struts.xml



来源:https://stackoverflow.com/questions/16049813/struts2-addactionerror-setting-result-to-input-automatically-on-redirect-result

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!