You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by jk...@apache.org on 2015/08/17 16:42:17 UTC

tapestry-5 git commit: TAP5-1981: convert client-side values back to server-side values for validation

Repository: tapestry-5
Updated Branches:
  refs/heads/master 5ae93b9dd -> f7a6480e7


TAP5-1981: convert client-side values back to server-side values for validation


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/f7a6480e
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/f7a6480e
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/f7a6480e

Branch: refs/heads/master
Commit: f7a6480e742ae30ca1eaef7a532f516f852f3fd0
Parents: 5ae93b9
Author: Jochen Kemnade <jo...@eddyson.de>
Authored: Mon Aug 17 16:41:05 2015 +0200
Committer: Jochen Kemnade <jo...@eddyson.de>
Committed: Mon Aug 17 16:41:05 2015 +0200

----------------------------------------------------------------------
 .../TapestryBeanValidationIntegrationTests.java | 19 +++++++++++
 .../testapp/entities/BeanForTAP1981.java        | 18 ++++++++++
 .../testapp/pages/RadioGroupWithValidation.java | 35 ++++++++++++++++++++
 .../src/test/webapp/Index.tml                   |  3 ++
 .../test/webapp/RadioGroupWithValidation.tml    | 32 ++++++++++++++++++
 .../corelib/components/RadioGroup.java          |  5 +--
 6 files changed, 110 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/f7a6480e/tapestry-beanvalidator/src/test/java/org/apache/tapestry5/beanvalidator/integration/TapestryBeanValidationIntegrationTests.java
----------------------------------------------------------------------
diff --git a/tapestry-beanvalidator/src/test/java/org/apache/tapestry5/beanvalidator/integration/TapestryBeanValidationIntegrationTests.java b/tapestry-beanvalidator/src/test/java/org/apache/tapestry5/beanvalidator/integration/TapestryBeanValidationIntegrationTests.java
index 85d4d00..bfd9999 100644
--- a/tapestry-beanvalidator/src/test/java/org/apache/tapestry5/beanvalidator/integration/TapestryBeanValidationIntegrationTests.java
+++ b/tapestry-beanvalidator/src/test/java/org/apache/tapestry5/beanvalidator/integration/TapestryBeanValidationIntegrationTests.java
@@ -281,5 +281,24 @@ public class TapestryBeanValidationIntegrationTests extends SeleniumTestCase
                 getText(String.format(locatorTemplate, "minValue")));
 
     }
+    
+    //TAP5-1981
+    @Test
+    public void validate_with_radiogroup() throws Exception
+    {
+        openLinks("Radio Group with Validation");
+        
+        click("//div[@class='test1']/form/input[@value='3']");
+
+        clickAndWait("//div[@class='test1']/form/input[@type='submit']");
+
+        assertTextPresent("Radiogroup requires a value no larger than 2.");
+
+        click("//div[@class='test2']/form/input[@value='3']");
+
+        clickAndWait("//div[@class='test2']/form/div/div/input[@type='submit']");
+
+        assertTextPresent("Group2 must be less than or equal to 2");
+    }
 
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/f7a6480e/tapestry-beanvalidator/src/test/java/org/example/testapp/entities/BeanForTAP1981.java
----------------------------------------------------------------------
diff --git a/tapestry-beanvalidator/src/test/java/org/example/testapp/entities/BeanForTAP1981.java b/tapestry-beanvalidator/src/test/java/org/example/testapp/entities/BeanForTAP1981.java
new file mode 100644
index 0000000..7274604
--- /dev/null
+++ b/tapestry-beanvalidator/src/test/java/org/example/testapp/entities/BeanForTAP1981.java
@@ -0,0 +1,18 @@
+package org.example.testapp.entities;
+
+import javax.validation.constraints.Max;
+
+public class BeanForTAP1981 {
+
+  private int number;
+
+  @Max(2)
+  public int getNumber() {
+    return number;
+  }
+
+  public void setNumber(final int value) {
+    number = value;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/f7a6480e/tapestry-beanvalidator/src/test/java/org/example/testapp/pages/RadioGroupWithValidation.java
----------------------------------------------------------------------
diff --git a/tapestry-beanvalidator/src/test/java/org/example/testapp/pages/RadioGroupWithValidation.java b/tapestry-beanvalidator/src/test/java/org/example/testapp/pages/RadioGroupWithValidation.java
new file mode 100644
index 0000000..8531029
--- /dev/null
+++ b/tapestry-beanvalidator/src/test/java/org/example/testapp/pages/RadioGroupWithValidation.java
@@ -0,0 +1,35 @@
+package org.example.testapp.pages;
+
+import org.apache.tapestry5.FieldValidator;
+import org.apache.tapestry5.annotations.Component;
+import org.apache.tapestry5.annotations.Environmental;
+import org.apache.tapestry5.annotations.Persist;
+import org.apache.tapestry5.corelib.components.RadioGroup;
+import org.apache.tapestry5.services.PropertyEditContext;
+import org.example.testapp.entities.BeanForTAP1981;
+
+public class RadioGroupWithValidation {
+
+  @Component(parameters = { "value=bean.number", "validate=prop:beanValidator" })
+  private RadioGroup group2;
+
+  /* */
+  @Persist
+  private BeanForTAP1981 bean;
+
+  /* */
+  @Environmental
+  private PropertyEditContext context;
+
+  public BeanForTAP1981 getBean() {
+    if (bean == null) {
+      bean = new BeanForTAP1981();
+    }
+    return bean;
+  }
+
+  public FieldValidator getBeanValidator() {
+    return context.getValidator(group2);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/f7a6480e/tapestry-beanvalidator/src/test/webapp/Index.tml
----------------------------------------------------------------------
diff --git a/tapestry-beanvalidator/src/test/webapp/Index.tml b/tapestry-beanvalidator/src/test/webapp/Index.tml
index abc9dfa..e19eafb 100644
--- a/tapestry-beanvalidator/src/test/webapp/Index.tml
+++ b/tapestry-beanvalidator/src/test/webapp/Index.tml
@@ -32,6 +32,9 @@
             </li>            
             <li>
                 <t:pagelink page="NestedObjectDemo" t:context="true">NestedObject Demo (client validation enabled)</t:pagelink>
+            </li>
+            <li>
+            	<t:pagelink page="RadioGroupWithValidation">Radio Group with Validation</t:pagelink>
             </li>            
         </ul>
     </body>

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/f7a6480e/tapestry-beanvalidator/src/test/webapp/RadioGroupWithValidation.tml
----------------------------------------------------------------------
diff --git a/tapestry-beanvalidator/src/test/webapp/RadioGroupWithValidation.tml b/tapestry-beanvalidator/src/test/webapp/RadioGroupWithValidation.tml
new file mode 100644
index 0000000..f1123a1
--- /dev/null
+++ b/tapestry-beanvalidator/src/test/webapp/RadioGroupWithValidation.tml
@@ -0,0 +1,32 @@
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
+      xmlns:p="tapestry:parameter">
+    <body>
+     	<div class="test1">
+	     	<h1>test 1</h1>
+	        <t:form>
+	
+				<t:errors/>
+	            <t:RadioGroup value="bean.number" validate="max=2">
+	                <t:radio value="1"/>1<br/>
+	                <t:radio value="2"/>2<br/>
+					<t:radio value="3"/>3<br/>
+				</t:RadioGroup>
+	
+				<t:submit/>
+	        </t:form>
+		</div>
+     	<div class="test2">
+		
+			<h1>test 2</h1>
+			<t:BeanEditForm object="bean">
+				<p:number>
+					<t:comp t:id="group2">
+						<t:radio value="1"/>1<br/>
+						<t:radio value="2"/>2<br/>
+						<t:radio value="3"/>3<br/>
+					</t:comp>
+				</p:number>
+			</t:BeanEditForm>
+		</div>
+    </body>
+</html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/f7a6480e/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/RadioGroup.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/RadioGroup.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/RadioGroup.java
index cd594c1..053f056 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/RadioGroup.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/RadioGroup.java
@@ -170,19 +170,20 @@ public class RadioGroup implements Field
             return;
         }
         String rawValue = request.getParameter(controlName);
+        Object convertedValue = encoder.toValue(rawValue);
 
         tracker.recordInput(this, rawValue);
         try
         {
             if (validate != null)
-                fieldValidationSupport.validate(rawValue, resources, validate);
+                fieldValidationSupport.validate(convertedValue, resources, validate);
         }
         catch (ValidationException ex)
         {
             tracker.recordError(this, ex.getMessage());
         }
 
-        value = encoder.toValue(rawValue);
+        value = convertedValue;
     }
 
     /**