struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject svn commit: r1457722 - in /struts/struts2/trunk/xwork-core/src: main/java/com/opensymphony/xwork2/validator/ main/java/com/opensymphony/xwork2/validator/annotations/ test/java/com/opensymphony/xwork2/validator/
Date Mon, 18 Mar 2013 12:00:22 GMT
Author: lukaszlenart
Date: Mon Mar 18 12:00:22 2013
New Revision: 1457722

URL: http://svn.apache.org/r1457722
Log:
WW-4009 Improves RequiredFieldValidator annotation to match RequiredFieldValidator class

Modified:
    struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilder.java
    struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/RequiredFieldValidator.java
    struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationAction.java
    struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilderTest.java
    struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationExpAction.java

Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilder.java?rev=1457722&r1=1457721&r2=1457722&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilder.java
(original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilder.java
Mon Mar 18 12:00:22 2013
@@ -629,6 +629,7 @@ public class AnnotationValidationConfigu
                 .shortCircuit(v.shortCircuit())
                 .defaultMessage(v.message())
                 .messageKey(v.key())
+                .messageParams(v.messageParams())
                 .build();
     }
 

Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/RequiredFieldValidator.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/RequiredFieldValidator.java?rev=1457722&r1=1457721&r2=1457722&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/RequiredFieldValidator.java
(original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/RequiredFieldValidator.java
Mon Mar 18 12:00:22 2013
@@ -55,6 +55,12 @@ import java.lang.annotation.Target;
  * <td class='confluenceTd'>i18n key from language specific properties file.</td>
  * </tr>
  * <tr>
+ * <td class='confluenceTd'>messageParams</td>
+ * <td class='confluenceTd'>no</td>
+ * <td class='confluenceTd'>&nbsp;</td>
+ * <td class='confluenceTd'>Additional params to be used to customize message - will
be evaluated against the Value Stack</td>
+ * </tr>
+ * <tr>
  * <td class='confluenceTd'>fieldName</td>
  * <td class='confluenceTd'>no</td>
  * <td class='confluenceTd'>&nbsp;</td>
@@ -103,6 +109,11 @@ public @interface RequiredFieldValidator
     String key() default "";
 
     /**
+     * Additional params to be used to customize message - will be evaluated against the
Value Stack
+     */
+    String[] messageParams() default {};
+
+    /**
      * The optional fieldName for SIMPLE validator types.
      */
     String fieldName() default "";

Modified: struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationAction.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationAction.java?rev=1457722&r1=1457721&r2=1457722&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationAction.java
(original)
+++ struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationAction.java
Mon Mar 18 12:00:22 2013
@@ -11,6 +11,7 @@ import com.opensymphony.xwork2.validator
 import com.opensymphony.xwork2.validator.annotations.FieldExpressionValidator;
 import com.opensymphony.xwork2.validator.annotations.IntRangeFieldValidator;
 import com.opensymphony.xwork2.validator.annotations.RegexFieldValidator;
+import com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator;
 import com.opensymphony.xwork2.validator.annotations.ValidationParameter;
 
 /**
@@ -45,6 +46,8 @@ public class AnnotationValidationAction 
             messageParams = {"one", "two", "three"}, shortCircuit = true)
     @IntRangeFieldValidator(fieldName = "foo", key = "int.key", message = "Foo is out of
range!", max = "10", min = "1",
             messageParams = {"one", "two", "three"}, shortCircuit = true)
+    @RequiredFieldValidator(fieldName = "foo", key = "required.key", message = "Foo is required!",
+            messageParams = {"one", "two", "three"}, shortCircuit = true)
     public String execute() {
         return SUCCESS;
     }

Modified: struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilderTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilderTest.java?rev=1457722&r1=1457721&r2=1457722&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilderTest.java
(original)
+++ struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilderTest.java
Mon Mar 18 12:00:22 2013
@@ -23,6 +23,7 @@ import com.opensymphony.xwork2.validator
 import com.opensymphony.xwork2.validator.validators.FieldExpressionValidator;
 import com.opensymphony.xwork2.validator.validators.IntRangeFieldValidator;
 import com.opensymphony.xwork2.validator.validators.RegexFieldValidator;
+import com.opensymphony.xwork2.validator.validators.RequiredFieldValidator;
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
@@ -44,7 +45,7 @@ public class AnnotationValidationConfigu
         List<Validator> validators = manager.getValidators(AnnotationValidationAction.class,
null);
 
         // then
-        assertEquals(validators.size(), 10);
+        assertEquals(validators.size(), 11);
         for (Validator validator : validators) {
             validate(validator);
         }
@@ -61,7 +62,7 @@ public class AnnotationValidationConfigu
         ValueStack valueStack = container.getInstance(ValueStackFactory.class).createValueStack();
         valueStack.push(new AnnotationValidationExpAction());
 
-        assertEquals(validators.size(), 10);
+        assertEquals(validators.size(), 11);
         for (Validator validator : validators) {
             validator.setValueStack(valueStack);
             validate(validator);
@@ -89,9 +90,19 @@ public class AnnotationValidationConfigu
             validateFieldExpressionValidator((FieldExpressionValidator) validator);
         } else if (validator.getValidatorType().equals("int")) {
             validateIntRangeFieldValidator((IntRangeFieldValidator) validator);
+        } else if (validator.getValidatorType().equals("required")) {
+            validateRequiredFieldValidator((RequiredFieldValidator) validator);
         }
     }
 
+    private void validateRequiredFieldValidator(RequiredFieldValidator validator) {
+        assertEquals("foo", validator.getFieldName());
+        assertEquals("Foo is required!", validator.getDefaultMessage());
+        assertEquals("required.key", validator.getMessageKey());
+        assertTrue(Arrays.equals(new String[]{"one", "two", "three"}, validator.getMessageParameters()));
+        assertEquals(true, validator.isShortCircuit());
+    }
+
     private void validateIntRangeFieldValidator(IntRangeFieldValidator validator) {
         assertEquals("foo", validator.getFieldName());
         assertEquals("int.key", validator.getMessageKey());

Modified: struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationExpAction.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationExpAction.java?rev=1457722&r1=1457721&r2=1457722&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationExpAction.java
(original)
+++ struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationExpAction.java
Mon Mar 18 12:00:22 2013
@@ -11,6 +11,7 @@ import com.opensymphony.xwork2.validator
 import com.opensymphony.xwork2.validator.annotations.FieldExpressionValidator;
 import com.opensymphony.xwork2.validator.annotations.IntRangeFieldValidator;
 import com.opensymphony.xwork2.validator.annotations.RegexFieldValidator;
+import com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator;
 import com.opensymphony.xwork2.validator.annotations.ValidationParameter;
 
 import java.text.ParseException;
@@ -51,6 +52,8 @@ public class AnnotationValidationExpActi
     @IntRangeFieldValidator(fieldName = "foo", key = "int.key", message = "Foo is out of
range!",
             maxExpression = "${intMax}", minExpression = "${intMin}",
             messageParams = {"one", "two", "three"}, shortCircuit = true)
+    @RequiredFieldValidator(fieldName = "foo", key = "required.key", message = "Foo is required!",
+            messageParams = {"one", "two", "three"}, shortCircuit = true)
     public String execute() {
         return SUCCESS;
     }



Mime
View raw message