Commits

Anonymous committed 926b8ef

XW-571
- nested visitor validators break short-circuit functionality

git-svn-id: http://svn.opensymphony.com/svn/xwork/branches/xwork_1-2@1674e221344d-f017-0410-9bd5-d282ab1896d7

Comments (0)

Files changed (2)

src/java/com/opensymphony/xwork/validator/AbstractActionValidatorManager.java

 
 import java.util.*;
 
+import com.opensymphony.xwork.validator.validators.VisitorFieldValidator;
+
 /**
  * <p/>An abstract implementation of {@link ActionValidatorManager} interface that contains the logics of
  * validating action objects and utlity methods common to all subclass eg. method to build validator
 
                 if (validator instanceof FieldValidator) {
                     fValidator = (FieldValidator) validator;
-                    fullFieldName = fValidator.getValidatorContext().getFullFieldName(fValidator.getFieldName());
+                    fullFieldName = new InternalValidatorContextWrapper(fValidator.getValidatorContext()).getFullFieldName(fValidator.getFieldName());
 
                     if ((shortcircuitedFields != null) && shortcircuitedFields.contains(fullFieldName)) {
                         if (LOG.isDebugEnabled()) {
         }
         return validators;
     }
+
+
+    protected class InternalValidatorContextWrapper {
+        private ValidatorContext validatorContext = null;
+
+        InternalValidatorContextWrapper(ValidatorContext validatorContext) {
+            this.validatorContext = validatorContext;
+        }
+
+        public String getFullFieldName(String field) {
+            if (validatorContext instanceof VisitorFieldValidator.AppendingValidatorContext) {
+                VisitorFieldValidator.AppendingValidatorContext appendingValidatorContext =
+                        (VisitorFieldValidator.AppendingValidatorContext) validatorContext;
+                return appendingValidatorContext.getFullFieldNameFromParent(field);
+            }
+            return validatorContext.getFullFieldName(field);
+        }
+
+    }
 }

src/java/com/opensymphony/xwork/validator/validators/VisitorFieldValidator.java

 
         if (appendPrefix) {
             validatorContext = new AppendingValidatorContext(getValidatorContext(), o, fieldName, getMessage(o));
+            setValidatorContext(validatorContext);
         } else {
             ValidatorContext parent = getValidatorContext();
             validatorContext = new DelegatingValidatorContext(parent, DelegatingValidatorContext.makeTextProvider(o, parent), parent);
+            setValidatorContext(validatorContext);
         }
 
         ActionValidatorManagerFactory.getInstance().validate(o, visitorContext, validatorContext);
     }
 
 
-    private class AppendingValidatorContext extends DelegatingValidatorContext {
-        Object o;
-        String field;
-        String message;
+    public class AppendingValidatorContext extends DelegatingValidatorContext {
+        private Object o;
+        private String field;
+        private String message;
+        private ValidatorContext parentValidatorContext;
+
 
         public AppendingValidatorContext(ValidatorContext parent, Object object, String field, String message) {
             super(parent, makeTextProvider(object, parent), parent);
 
-            //            super(parent);
             this.field = field;
             this.message = message;
+            parentValidatorContext = parent;
         }
 
         /**
             return field + "." + fieldName;
         }
 
+        public String getFullFieldNameFromParent(String fieldName) {
+            return parentValidatorContext.getFullFieldName(field+"."+fieldName);
+        }
+
         public void addActionError(String anErrorMessage) {
             super.addFieldError(field, message + anErrorMessage);
         }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.