You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by ba...@apache.org on 2019/03/29 18:28:14 UTC

[tapestry-5] branch 5.4.x updated: TAP5-2075 / TAP5-2610 - required validation should not be added to checkbox when primitive boolean is behind it, unless checked or required validation is explicitly added

This is an automated email from the ASF dual-hosted git repository.

balapal pushed a commit to branch 5.4.x
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git


The following commit(s) were added to refs/heads/5.4.x by this push:
     new 364ea63  TAP5-2075 / TAP5-2610 - required validation should not be added to checkbox when primitive boolean is behind it, unless checked or required validation is explicitly added
364ea63 is described below

commit 364ea6346baaa02b55bbd04ed52379a3f3f0f074
Author: Balázs Palcsó <pa...@gmail.com>
AuthorDate: Fri Mar 29 19:28:05 2019 +0100

    TAP5-2075 / TAP5-2610 - required validation should not be added to checkbox when primitive boolean is behind it, unless checked or required validation is explicitly added
---
 .../internal/beaneditor/PrimitiveFieldConstraintGenerator.java   | 5 +++--
 .../apache/tapestry5/services/ValidationConstraintGenerator.java | 2 +-
 tapestry-core/src/test/app3/Html5Support.tml                     | 3 +++
 .../tapestry5/integration/app3/AdditionalIntegrationTests.java   | 7 ++++++-
 .../apache/tapestry5/integration/app3/pages/Html5Support.java    | 9 +++++++++
 5 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/beaneditor/PrimitiveFieldConstraintGenerator.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/beaneditor/PrimitiveFieldConstraintGenerator.java
index 7dcc77c..440b6a4 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/beaneditor/PrimitiveFieldConstraintGenerator.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/beaneditor/PrimitiveFieldConstraintGenerator.java
@@ -27,9 +27,10 @@ public class PrimitiveFieldConstraintGenerator implements ValidationConstraintGe
 {
     private final List<String> REQUIRED = Arrays.asList("required");
 
-    public List<String> buildConstraints(Class propertyType, AnnotationProvider annotationProvider)
+    @Override
+    public List<String> buildConstraints(Class<?> propertyType, AnnotationProvider annotationProvider)
     {
-        return propertyType.isPrimitive() ? REQUIRED : null;
+        return propertyType.isPrimitive() && !"boolean".equals(propertyType.getName()) ? REQUIRED : null;
     }
 
 }
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/ValidationConstraintGenerator.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/ValidationConstraintGenerator.java
index c9472b3..55d55a4 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/services/ValidationConstraintGenerator.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/ValidationConstraintGenerator.java
@@ -42,5 +42,5 @@ public interface ValidationConstraintGenerator
      * @return a list of constraints
      * @see FieldValidatorSource
      */
-    List<String> buildConstraints(Class propertyType, AnnotationProvider annotationProvider);
+    List<String> buildConstraints(Class<?> propertyType, AnnotationProvider annotationProvider);
 }
diff --git a/tapestry-core/src/test/app3/Html5Support.tml b/tapestry-core/src/test/app3/Html5Support.tml
index 5776c36..2841de8 100644
--- a/tapestry-core/src/test/app3/Html5Support.tml
+++ b/tapestry-core/src/test/app3/Html5Support.tml
@@ -12,6 +12,9 @@
 			<input t:type="TextField" t:id="maxNumber" t:validate="max=10" t:mixins="FormGroup"/>
 			<input t:type="TextField" t:id="minMaxNumber" t:validate="min=2,max=4" t:mixins="FormGroup"/>
 			<input t:type="TextField" t:id="regexp" t:validate="regexp=[0-9]{2}" t:mixins="FormGroup"/>
+			<input t:type="CheckBox" t:id="bool" t:mixins="FormGroup"/>
+			<input t:type="CheckBox" t:id="mustBeCheckedBoolean" t:validate="checked" t:mixins="FormGroup"/>
+			<input t:type="CheckBox" t:id="requiredBoolean" t:validate="required" t:mixins="FormGroup"/>
 			<input type="submit"/>
 		</form>
     </body>
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/AdditionalIntegrationTests.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/AdditionalIntegrationTests.java
index 2b8a7e2..8c755fe 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/AdditionalIntegrationTests.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/AdditionalIntegrationTests.java
@@ -122,7 +122,12 @@ public class AdditionalIntegrationTests extends TapestryCoreTestCase
         assertEquals("number", getAttribute("minMaxNumber@type"));
         assertEquals("2", getAttribute("minMaxNumber@min"));
         assertEquals("4", getAttribute("minMaxNumber@max"));
-        
+
+        assertEquals(getAttribute("bool@required"), null);
+
+        assertEquals(getAttribute("mustBeCheckedBoolean@required"), "required");
+
+        assertEquals(getAttribute("requiredBoolean@required"), "required");
     }
 
 }
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/pages/Html5Support.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/pages/Html5Support.java
index 2ee9029..ee4c083 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/pages/Html5Support.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/pages/Html5Support.java
@@ -40,4 +40,13 @@ public class Html5Support
     @Property
     private String regexp;
 
+    @Property
+    private boolean bool;
+
+    @Property
+    private boolean mustBeCheckedBoolean;
+
+    @Property
+    private boolean requiredBoolean;
+
 }