Search in sources :

Example 1 with ValidationInterceptor

use of com.opensymphony.xwork2.validator.ValidationInterceptor in project struts by apache.

the class Form method evaluateClientSideJsEnablement.

/**
 * Evaluate client side JavaScript Enablement.
 * @param actionName the actioName to check for
 * @param namespace the namespace to check for
 * @param actionMethod the method to ckeck for
 */
protected void evaluateClientSideJsEnablement(String actionName, String namespace, String actionMethod) {
    // Only evaluate if Client-Side js is to be enable when validate=true
    Boolean validate = (Boolean) getParameters().get("validate");
    if (validate != null && validate) {
        addParameter("performValidation", Boolean.FALSE);
        RuntimeConfiguration runtimeConfiguration = configuration.getRuntimeConfiguration();
        ActionConfig actionConfig = runtimeConfiguration.getActionConfig(namespace, actionName);
        if (actionConfig != null) {
            List<InterceptorMapping> interceptors = actionConfig.getInterceptors();
            for (InterceptorMapping interceptorMapping : interceptors) {
                if (ValidationInterceptor.class.isInstance(interceptorMapping.getInterceptor())) {
                    ValidationInterceptor validationInterceptor = (ValidationInterceptor) interceptorMapping.getInterceptor();
                    Set excludeMethods = validationInterceptor.getExcludeMethodsSet();
                    Set includeMethods = validationInterceptor.getIncludeMethodsSet();
                    if (MethodFilterInterceptorUtil.applyMethod(excludeMethods, includeMethods, actionMethod)) {
                        addParameter("performValidation", Boolean.TRUE);
                    }
                    return;
                }
            }
        }
    }
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) Set(java.util.Set) InterceptorMapping(com.opensymphony.xwork2.config.entities.InterceptorMapping) RuntimeConfiguration(com.opensymphony.xwork2.config.RuntimeConfiguration)

Example 2 with ValidationInterceptor

use of com.opensymphony.xwork2.validator.ValidationInterceptor in project struts by apache.

the class ValidationInterceptorPrefixMethodInvocationTest method testPrefixMethodInvocation2.

public void testPrefixMethodInvocation2() throws Exception {
    method = "save";
    result = "okok";
    ValidationInterceptor interceptor = create();
    String result = interceptor.intercept(invocation);
    assertEquals("okok", result);
}
Also used : ValidationInterceptor(com.opensymphony.xwork2.validator.ValidationInterceptor)

Example 3 with ValidationInterceptor

use of com.opensymphony.xwork2.validator.ValidationInterceptor in project struts by apache.

the class DefaultWorkflowInterceptorTest method testIncludesAndExcludesMethodWithIncludeWildcard.

public void testIncludesAndExcludesMethodWithIncludeWildcard() throws Exception {
    interceptor.setExcludeMethods("input,validate");
    interceptor.setIncludeMethods("*");
    ValidationInterceptor validationInterceptor = create();
    validationInterceptor.setExcludeMethods("input,validate");
    validationInterceptor.setIncludeMethods("*");
    validationInterceptor.intercept(invocation);
    assertEquals(result, interceptor.intercept(invocation));
}
Also used : ValidationInterceptor(com.opensymphony.xwork2.validator.ValidationInterceptor)

Example 4 with ValidationInterceptor

use of com.opensymphony.xwork2.validator.ValidationInterceptor in project struts by apache.

the class DefaultWorkflowInterceptorTest method testIncludesAndExcludesMethodWithExcludeWildcard.

public void testIncludesAndExcludesMethodWithExcludeWildcard() throws Exception {
    interceptor.setExcludeMethods("*");
    interceptor.setIncludeMethods("execute");
    ValidationInterceptor validationInterceptor = create();
    validationInterceptor.setExcludeMethods("*");
    validationInterceptor.setIncludeMethods("execute");
    validationInterceptor.intercept(invocation);
    assertEquals(result, interceptor.intercept(invocation));
}
Also used : ValidationInterceptor(com.opensymphony.xwork2.validator.ValidationInterceptor)

Example 5 with ValidationInterceptor

use of com.opensymphony.xwork2.validator.ValidationInterceptor in project struts by apache.

the class DefaultWorkflowInterceptorTest method testIncludesAndExcludesMethodAllWildCarded.

public void testIncludesAndExcludesMethodAllWildCarded() throws Exception {
    interceptor.setExcludeMethods("*");
    interceptor.setIncludeMethods("*");
    ValidationInterceptor validationInterceptor = create();
    validationInterceptor.setExcludeMethods("*");
    validationInterceptor.setIncludeMethods("*");
    validationInterceptor.intercept(invocation);
    assertEquals(result, interceptor.intercept(invocation));
}
Also used : ValidationInterceptor(com.opensymphony.xwork2.validator.ValidationInterceptor)

Aggregations

ValidationInterceptor (com.opensymphony.xwork2.validator.ValidationInterceptor)18 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)5 InterceptorMapping (com.opensymphony.xwork2.config.entities.InterceptorMapping)4 RuntimeConfiguration (com.opensymphony.xwork2.config.RuntimeConfiguration)2 ActionContext (com.opensymphony.xwork2.ActionContext)1 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)1 ActionProxy (com.opensymphony.xwork2.ActionProxy)1 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)1 ResultConfig (com.opensymphony.xwork2.config.entities.ResultConfig)1 ContainerBuilder (com.opensymphony.xwork2.inject.ContainerBuilder)1 ParametersInterceptor (com.opensymphony.xwork2.interceptor.ParametersInterceptor)1 MockActionInvocation (com.opensymphony.xwork2.mock.MockActionInvocation)1 MockActionProxy (com.opensymphony.xwork2.mock.MockActionProxy)1 MockResult (com.opensymphony.xwork2.mock.MockResult)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 ActionMapper (org.apache.struts2.dispatcher.mapper.ActionMapper)1 DefaultActionMapper (org.apache.struts2.dispatcher.mapper.DefaultActionMapper)1