一個例子,原來的
<interceptor-ref name="validation"/>
<interceptor-ref name="workflow"/>
可改寫為
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel</param>
</interceptor-ref>
<interceptor-ref name="workflow">
<param name="excludeMethods">input,back,cancel</param>
</interceptor-ref>
那么,對于簡單的需驗證頁面,不需要再因為避免不必要的校驗而分兩個action。
只有com.opensymphony.xwork.validator.ValidationInterceptor, com.opensymphony.xwork.interceptor.DefaultWorkflowInterceptor 定義并實現了這個excludeMethods,實現的也還是比較粗糙的,我們在做類似實現的時候可以參考一下,有必要也可以改進,擴展一下,例如增加includeMethods
public void setExcludeMethods(String excludeMethods) {
this.excludeMethods = TextParseUtil.commaDelimitedStringToSet(excludeMethods);
}
public String intercept(ActionInvocation invocation) throws Exception {
if (excludeMethods.contains(invocation.getProxy().getMethod())) {
log.debug("Skipping workflow. Method found in exclude list.");
return invocation.invoke();
}


}