Author: drobiazko
Date: Thu Jun 23 10:25:55 2011
New Revision: 1138816

URL: http://svn.apache.org/viewvc?rev=1138816&view=rev
Log:
TAP5-1550: Allow Checklist component to be validated by Bean Validation API 
constraints

Modified:
    
tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/apache/tapestry5/beanvalidator/integration/TapestryBeanValidationIntegrationTests.java
    
tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/example/testapp/pages/FormValidationDemo.java
    
tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/webapp/FormValidationDemo.tml
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Checklist.java

Modified: 
tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/apache/tapestry5/beanvalidator/integration/TapestryBeanValidationIntegrationTests.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/apache/tapestry5/beanvalidator/integration/TapestryBeanValidationIntegrationTests.java?rev=1138816&r1=1138815&r2=1138816&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/apache/tapestry5/beanvalidator/integration/TapestryBeanValidationIntegrationTests.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/apache/tapestry5/beanvalidator/integration/TapestryBeanValidationIntegrationTests.java
 Thu Jun 23 10:25:55 2011
@@ -37,6 +37,7 @@ public class TapestryBeanValidationInteg
         assertTextPresent("Secret Password may not be null");
         assertTextPresent("Programming Languages size must be between 2 and 
3");
         assertTextPresent("Favorite Colors may not be null");
+        assertTextPresent("More Colors size must be between 3 and 4");
         assertTextPresent("Birth Day may not be null");
         
 
@@ -56,17 +57,23 @@ public class TapestryBeanValidationInteg
        assertFalse(isTextPresent("Secret Password may not be null"));
        assertFalse(isTextPresent("Programming Languages size must be between 2 
and 3"));
        assertFalse(isTextPresent("Favorite Colors may not be null"));
+        assertTextPresent("More Colors size must be between 3 and 4");
        assertTextPresent("Birth Day must be in the past");
         
         //Test Tapestry validator
         
         type("loginName", "igor");
         type("birthDay", "6.04.1978");
+
+        check("//input[@value='White']");
+        check("//input[@value='Yellow']");
+        check("//input[@value='Orange']");
        
        clickAndWait(SUBMIT);
        
        assertTextPresent("You must provide at least 5 characters for Login 
Name.");
        assertFalse(isTextPresent("Birth Day must be in the past"));
+       assertFalse(isTextPresent("More Colors size must be between 3 and 4"));
         
         type("loginName", "igor123");
        

Modified: 
tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/example/testapp/pages/FormValidationDemo.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/example/testapp/pages/FormValidationDemo.java?rev=1138816&r1=1138815&r2=1138816&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/example/testapp/pages/FormValidationDemo.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/example/testapp/pages/FormValidationDemo.java
 Thu Jun 23 10:25:55 2011
@@ -26,39 +26,45 @@ import org.apache.tapestry5.beaneditor.V
 import org.apache.tapestry5.internal.services.StringValueEncoder;
 import org.example.testapp.services.Foo;
 
-public class FormValidationDemo 
+public class FormValidationDemo
 {
        @NotNull(groups=Foo.class)
        @Validate("minlength=5")
        @Property
        @Persist
        private String userName;
-       
+
        @NotNull
        @Property
        @Persist
        private String password;
-       
+
        @NotNull
        @Size(min=2, max=3)
        @Property
        @Persist
        private Collection<String> languages;
-       
+
        @NotNull
        @Property
        @Persist
-       private String color; 
-       
+       private String color;
+
+    @NotNull
+       @Size(min=3, max=4)
+       @Property
+       @Persist
+       private Collection<String> moreColors;
+
        @NotNull
        @Past
        @Property
        @Persist
-       private Date date; 
-       
+       private Date date;
+
        public StringValueEncoder getStringValueEncoder()
        {
                return new StringValueEncoder();
        }
-       
+
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/webapp/FormValidationDemo.tml
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/webapp/FormValidationDemo.tml?rev=1138816&r1=1138815&r2=1138816&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/webapp/FormValidationDemo.tml
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/webapp/FormValidationDemo.tml
 Thu Jun 23 10:25:55 2011
@@ -16,6 +16,10 @@
                
                <br/>
                <t:select t:id="favoriteColors" model="literal:Red,Green,Blue" 
value="color"/>
+
+            <br/>
+            <label t:type="label" for="moreColors"/>
+               <t:checklist t:id="moreColors" 
model="literal:White,Yellow,Orange,Pink" selected="moreColors" 
encoder="stringValueEncoder"/>
                
                <br/>
                <t:datefield t:id="birthDay" value="date" format="dd.MM.yyyy"/>

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Checklist.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Checklist.java?rev=1138816&r1=1138815&r2=1138816&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Checklist.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Checklist.java
 Thu Jun 23 10:25:55 2011
@@ -150,6 +150,8 @@ public class Checklist extends AbstractF
 
         }
 
+        putPropertyNameIntoBeanValidationContext("selected");
+
         try
         {
             this.fieldValidationSupport.validate(selected, 
this.componentResources, this.validate);
@@ -159,6 +161,8 @@ public class Checklist extends AbstractF
         {
             this.tracker.recordError(this, e.getMessage());
         }
+
+        removePropertyNameFromBeanValidationContext();
     }
 
     Set<Object> getSelected()


Reply via email to