李李的技术博客

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  13 随笔 :: 0 文章 :: 55 评论 :: 0 Trackbacks

2005年12月3日 #

一个例子,原来的

<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();
        }
        
    }
posted @ 2005-12-03 22:29 李李 阅读(744) | 评论 (2)编辑 收藏