⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 validationinterceptor.java

📁 spring struts hibernate
💻 JAVA
字号:
package org.appfuse.webapp.interceptor;

import java.util.Map;

import com.opensymphony.webwork.ServletActionContext;
import com.opensymphony.xwork.Action;
import com.opensymphony.xwork.ActionContext;
import com.opensymphony.xwork.ActionInvocation;
import com.opensymphony.xwork.interceptor.AroundInterceptor;
import com.opensymphony.xwork.validator.ActionValidatorManager;


/**
 * Custom ValidationInterceptor to cancel validation when cancel 
 * or delete is in request.
 */
public class ValidationInterceptor extends AroundInterceptor {

    protected void after(ActionInvocation dispatcher, String result) throws Exception {
    }

    protected void before(ActionInvocation invocation) throws Exception {
        Action action = invocation.getAction();
        String context = invocation.getProxy().getActionName();
        
        final Map parameters = ActionContext.getContext().getParameters();
        // don't validate on cancel, delete or GET
        if (ServletActionContext.getRequest().getMethod().equals("GET")) {
            if (log.isDebugEnabled()) {
                log.debug("Cancelling validation, detected GET request");
            }
        } else if (parameters.containsKey("cancel")  || parameters.containsKey("delete")) {
            if (log.isDebugEnabled()) {
                log.debug("Cancelling validation, detected clicking cancel or delete");
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Validating " + invocation.getProxy().getNamespace() + invocation.getProxy().getActionName() + ".");
            }
    
            ActionValidatorManager.validate(action, context);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -