質問

If I understand, the Struts 2 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?

役に立ちましたか?

解決

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.

他のヒント

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

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top