diff --git a/core/src/main/java/org/apache/struts2/interceptor/validation/JSONValidationInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/validation/JSONValidationInterceptor.java index 95e851c98..0cedc1c3b 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/validation/JSONValidationInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/validation/JSONValidationInterceptor.java @@ -34,6 +34,7 @@ import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.ActionInvocation; +import com.opensymphony.xwork2.ModelDriven; import com.opensymphony.xwork2.ValidationAware; import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor; import com.opensymphony.xwork2.util.logging.Logger; @@ -43,7 +44,7 @@ import com.opensymphony.xwork2.util.logging.LoggerFactory; *
Serializes validation and action errors into JSON. This interceptor does not * perform any validation, so it must follow the 'validation' interceptor on the stack. *
- * + * *This stack (defined in struts-default.xml) shows how to use this interceptor with the * 'validation' interceptor
*@@ -58,19 +59,19 @@ import com.opensymphony.xwork2.util.logging.LoggerFactory; **
If 'validationFailedStatus' is set it will be used as the Response status * when validation fails.
- * - *If the request has a parameter 'struts.validateOnly' execution will return after + * + *
If the request has a parameter 'struts.validateOnly' execution will return after * validation (action won't be executed).
- * + * *A request parameter named 'enableJSONValidation' must be set to 'true' to * use this interceptor
*/ public class JSONValidationInterceptor extends MethodFilterInterceptor { private static final Logger LOG = LoggerFactory.getLogger(JSONValidationInterceptor.class); - + private static final String VALIDATE_ONLY_PARAM = "struts.validateOnly"; private static final String VALIDATE_JSON_PARAM = "struts.enableJSONValidation"; - + static char[] hex = "0123456789ABCDEF".toCharArray(); private int validationFailedStatus = -1; @@ -90,7 +91,7 @@ public class JSONValidationInterceptor extends MethodFilterInterceptor { Object action = invocation.getAction(); String jsonEnabled = request.getParameter(VALIDATE_JSON_PARAM); - + if (jsonEnabled != null && "true".equals(jsonEnabled)) { if (action instanceof ValidationAware) { // generate json @@ -130,7 +131,7 @@ public class JSONValidationInterceptor extends MethodFilterInterceptor { //action errors if (validationAware.hasActionErrors()) { sb.append("\"errors\":"); - sb.append(buildArray(validationAware.getActionErrors())); + sb.append(buildArray(validationAware.getActionErrors())); } //field errors @@ -143,7 +144,9 @@ public class JSONValidationInterceptor extends MethodFilterInterceptor { for (Map.Entry