一个例子,原来的
<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();
}
}