struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [1/3] git commit: get correct full field name in visitor field validator
Date Fri, 27 Jun 2014 11:40:31 GMT
Repository: struts
Updated Branches:
  refs/heads/develop 63de7730e -> 3a07c3177


get correct full field name in visitor field validator


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/2b8a805e
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/2b8a805e
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/2b8a805e

Branch: refs/heads/develop
Commit: 2b8a805eb0794abd5c804c0bc9059e56b72c985f
Parents: 63897e8
Author: Aleksandr Mashchenko <aleksandr.7m@gmail.com>
Authored: Wed May 14 20:22:29 2014 +0300
Committer: Aleksandr Mashchenko <aleksandr.7m@gmail.com>
Committed: Wed May 14 20:22:29 2014 +0300

----------------------------------------------------------------------
 .../AnnotationActionValidatorManager.java       | 42 +----------------
 .../DefaultActionValidatorManager.java          | 49 +-------------------
 .../validators/VisitorFieldValidator.java       | 13 ++++--
 3 files changed, 10 insertions(+), 94 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/2b8a805e/xwork-core/src/main/java/com/opensymphony/xwork2/validator/AnnotationActionValidatorManager.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/validator/AnnotationActionValidatorManager.java
b/xwork-core/src/main/java/com/opensymphony/xwork2/validator/AnnotationActionValidatorManager.java
index 6f1d548..9b6beb3 100644
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/validator/AnnotationActionValidatorManager.java
+++ b/xwork-core/src/main/java/com/opensymphony/xwork2/validator/AnnotationActionValidatorManager.java
@@ -154,7 +154,7 @@ public class AnnotationActionValidatorManager implements ActionValidatorManager
 
                 if (validator instanceof FieldValidator) {
                     fValidator = (FieldValidator) validator;
-                    fullFieldName = new InternalValidatorContextWrapper(fValidator.getValidatorContext()).getFullFieldName(fValidator.getFieldName());
+                    fullFieldName = fValidator.getValidatorContext().getFullFieldName(fValidator.getFieldName());
 
                     if ((shortcircuitedFields != null) && shortcircuitedFields.contains(fullFieldName))
{
                         if (LOG.isDebugEnabled()) {
@@ -412,44 +412,4 @@ public class AnnotationActionValidatorManager implements ActionValidatorManager
 
         return retList;
     }
-
-
-    /**
-     * An {@link com.opensymphony.xwork2.validator.ValidatorContext} wrapper that
-     * returns the full field name
-     * {@link AnnotationActionValidatorManager.InternalValidatorContextWrapper#getFullFieldName(String)}
-     * by consulting it's parent if its an {@link com.opensymphony.xwork2.validator.validators.VisitorFieldValidator.AppendingValidatorContext}.
-     * <p/>
-     * Eg. if we have nested Visitor
-     * AddressVisitor nested inside PersonVisitor, when using the normal #getFullFieldName,
we will get
-     * "address.somefield", we lost the parent, with this wrapper, we will get "person.address.somefield".
-     * This is so that the key is used to register errors, so that we don't screw up short-curcuit
feature
-     * when using nested visitor. See XW-571 (nested visitor validators break short-circuit
functionality)
-     * at http://jira.opensymphony.com/browse/XW-571
-     */
-    protected class InternalValidatorContextWrapper {
-        private ValidatorContext validatorContext = null;
-
-        InternalValidatorContextWrapper(ValidatorContext validatorContext) {
-            this.validatorContext = validatorContext;
-        }
-
-        /**
-         * Get the full field name by consulting the parent, so that when we are using nested
visitors (
-         * visitor nested inside visitor etc.) we still get the full field name including
its parents.
-         * See XW-571 for more details.
-         *
-         * @param field
-         * @return String
-         */
-        public String getFullFieldName(String field) {
-            if (validatorContext instanceof VisitorFieldValidator.AppendingValidatorContext)
{
-                VisitorFieldValidator.AppendingValidatorContext appendingValidatorContext
=
-                        (VisitorFieldValidator.AppendingValidatorContext) validatorContext;
-                return appendingValidatorContext.getFullFieldNameFromParent(field);
-            }
-            return validatorContext.getFullFieldName(field);
-        }
-
-    }
 }

http://git-wip-us.apache.org/repos/asf/struts/blob/2b8a805e/xwork-core/src/main/java/com/opensymphony/xwork2/validator/DefaultActionValidatorManager.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/validator/DefaultActionValidatorManager.java
b/xwork-core/src/main/java/com/opensymphony/xwork2/validator/DefaultActionValidatorManager.java
index 30dad54..b6d0211 100644
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/validator/DefaultActionValidatorManager.java
+++ b/xwork-core/src/main/java/com/opensymphony/xwork2/validator/DefaultActionValidatorManager.java
@@ -140,14 +140,7 @@ public class DefaultActionValidatorManager implements ActionValidatorManager
{
 
                 if (validator instanceof FieldValidator) {
                     fValidator = (FieldValidator) validator;
-                    fullFieldName = new InternalValidatorContextWrapper(fValidator.getValidatorContext()).getFullFieldName(fValidator.getFieldName());
-
-                    // This is pretty crap, but needed to support short-circuited validations
on nested visited objects
-                    if (validatorContext instanceof VisitorFieldValidator.AppendingValidatorContext)
{
-                        VisitorFieldValidator.AppendingValidatorContext appendingValidatorContext
=
-                                (VisitorFieldValidator.AppendingValidatorContext) validatorContext;
-                        fullFieldName = appendingValidatorContext.getFullFieldNameFromParent(fValidator.getFieldName());
-                    }
+                    fullFieldName = fValidator.getValidatorContext().getFullFieldName(fValidator.getFieldName());
 
                     if ((shortcircuitedFields != null) && shortcircuitedFields.contains(fullFieldName))
{
                         if (LOG.isDebugEnabled()) {
@@ -361,44 +354,4 @@ public class DefaultActionValidatorManager implements ActionValidatorManager
{
 
         return retList;
     }
-
-
-    /**
-     * An {@link com.opensymphony.xwork2.validator.ValidatorContext} wrapper that
-     * returns the full field name
-     * {@link InternalValidatorContextWrapper#getFullFieldName(String)}
-     * by consulting it's parent if its an {@link com.opensymphony.xwork2.validator.validators.VisitorFieldValidator.AppendingValidatorContext}.
-     * <p/>
-     * Eg. if we have nested Visitor
-     * AddressVisitor nested inside PersonVisitor, when using the normal #getFullFieldName,
we will get
-     * "address.somefield", we lost the parent, with this wrapper, we will get "person.address.somefield".
-     * This is so that the key is used to register errors, so that we don't screw up short-curcuit
feature
-     * when using nested visitor. See XW-571 (nested visitor validators break short-circuit
functionality)
-     * at http://jira.opensymphony.com/browse/XW-571
-     */
-    protected class InternalValidatorContextWrapper {
-        private ValidatorContext validatorContext = null;
-
-        InternalValidatorContextWrapper(ValidatorContext validatorContext) {
-            this.validatorContext = validatorContext;
-        }
-
-        /**
-         * Get the full field name by consulting the parent, so that when we are using nested
visitors (
-         * visitor nested inside visitor etc.) we still get the full field name including
its parents.
-         * See XW-571 for more details.
-         * @param field The field name
-         * @return String
-         */
-        public String getFullFieldName(String field) {
-            if (validatorContext instanceof VisitorFieldValidator.AppendingValidatorContext)
{
-                VisitorFieldValidator.AppendingValidatorContext appendingValidatorContext
=
-                        (VisitorFieldValidator.AppendingValidatorContext) validatorContext;
-                return appendingValidatorContext.getFullFieldNameFromParent(field);
-            }
-            return validatorContext.getFullFieldName(field);
-        }
-
-    }    
-
 }

http://git-wip-us.apache.org/repos/asf/struts/blob/2b8a805e/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/VisitorFieldValidator.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/VisitorFieldValidator.java
b/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/VisitorFieldValidator.java
index 1310e10..e0be5f0 100644
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/VisitorFieldValidator.java
+++ b/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/VisitorFieldValidator.java
@@ -192,25 +192,28 @@ public class VisitorFieldValidator extends FieldValidatorSupport {
          * Translates a simple field name into a full field name in Ognl syntax
          *
          * @param fieldName field name in OGNL syntax
-         * @return field name in OGNL syntax
+         * @return full field name in OGNL syntax
          */
         @Override
         public String getFullFieldName(String fieldName) {
+            if (parent instanceof VisitorFieldValidator.AppendingValidatorContext) {
+                return parent.getFullFieldName(field + "." + fieldName);
+            }
             return field + "." + fieldName;
         }
 
-        public String getFullFieldNameFromParent(String fieldName) {
-            return parent.getFullFieldName(field + "." + fieldName);
+        public String getFieldNameWithField(String fieldName) {
+            return field + "." + fieldName;
         }
 
         @Override
         public void addActionError(String anErrorMessage) {
-            super.addFieldError(getFullFieldName(field), message + anErrorMessage);
+            super.addFieldError(getFieldNameWithField(field), message + anErrorMessage);
         }
 
         @Override
         public void addFieldError(String fieldName, String errorMessage) {
-            super.addFieldError(getFullFieldName(fieldName), message + errorMessage);
+            super.addFieldError(getFieldNameWithField(fieldName), message + errorMessage);
         }
     }
 }


Mime
View raw message