You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by mu...@apache.org on 2008/07/16 23:01:57 UTC
svn commit: r677429 -
/struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/validation/JSONValidationInterceptor.java
Author: musachy
Date: Wed Jul 16 14:01:56 2008
New Revision: 677429
URL: http://svn.apache.org/viewvc?rev=677429&view=rev
Log:
WW-2721 Ajax Validation does not work with ModelDriven Actions
Thanks to Wolfgang Schröder for the patch
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/validation/JSONValidationInterceptor.java
Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/validation/JSONValidationInterceptor.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/validation/JSONValidationInterceptor.java?rev=677429&r1=677428&r2=677429&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/validation/JSONValidationInterceptor.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/validation/JSONValidationInterceptor.java Wed Jul 16 14:01:56 2008
@@ -34,6 +34,7 @@
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 @@
* <p>Serializes validation and action errors into JSON. This interceptor does not
* perform any validation, so it must follow the 'validation' interceptor on the stack.
* </p>
- *
+ *
* <p>This stack (defined in struts-default.xml) shows how to use this interceptor with the
* 'validation' interceptor</p>
* <pre>
@@ -58,19 +59,19 @@
* </pre>
* <p>If 'validationFailedStatus' is set it will be used as the Response status
* when validation fails.</p>
- *
- * <p>If the request has a parameter 'struts.validateOnly' execution will return after
+ *
+ * <p>If the request has a parameter 'struts.validateOnly' execution will return after
* validation (action won't be executed).</p>
- *
+ *
* <p>A request parameter named 'enableJSONValidation' must be set to 'true' to
* use this interceptor</p>
*/
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 @@
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 @@
//action errors
if (validationAware.hasActionErrors()) {
sb.append("\"errors\":");
- sb.append(buildArray(validationAware.getActionErrors()));
+ sb.append(buildArray(validationAware.getActionErrors()));
}
//field errors
@@ -143,7 +144,9 @@
for (Map.Entry<String, List<String>> fieldError : fieldErrors
.entrySet()) {
sb.append("\"");
- sb.append(fieldError.getKey());
+ //if it is model driven, remove "model." see WW-2721
+ sb.append(validationAware instanceof ModelDriven ? fieldError.getKey().substring(6)
+ : fieldError.getKey());
sb.append("\":");
sb.append(buildArray(fieldError.getValue()));
sb.append(",");