Struts 2 WorkFlow Interceptor and actions that do not have an INPUT result

江枫思渺然 提交于 2019-12-11 18:59:28

问题


If I understand, the Struts2 interceptor stack correctly, the workflow interceptor looks to see if any validation failures have been reported by the validation interceptor. If it finds that there have been validation failures, it returns ( by default ) Action.INPUT

If this is the case, what happens if the Action that is being executed does not have an INPUT result defined in its struts.xml configuration?


回答1:


If it returns INPUT, and there is no result defined for that (and no general result), you'll get an error page that says something like

 No result defined for type INPUT and action <action name>.

You can define a general page that will always be shown for 'INPUT', but the better solution is that if you have a validate() method, it's usually a good idea to define an INPUT result to go back. Even if you don't explicitly do any validation, things like a non-integer value being passed to an integer field can cause that result, so it's a good idea to define it.




回答2:


You can use ValidationWorkflowAware interface to define result name per action

or

You can use InputConfig annotation to change the result name per action programatically

or

With upcoming new release of Struts version 2.3.15 it will be also possible to use ValidationErrorAware interface, actions can be notified about error and can change returned result name: https://issues.apache.org/jira/browse/WW-4071




回答3:


INPUT result is used by default, you could always override it via setting parameter to interceptor inputResultName.

<interceptor-ref name="workflow">
   <param name="inputResultName">error</param>
</interceptor-ref>

Further clarification and reference to workflow interceptor.

In the example above the action doesn't have an INPUT result and if action errors or field errors found then result ERROR will return.



来源:https://stackoverflow.com/questions/16691045/struts-2-workflow-interceptor-and-actions-that-do-not-have-an-input-result

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