You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2013/09/16 19:18:41 UTC

[1/2] git commit: Advance version number to 5.4-alpha-23

Updated Branches:
  refs/heads/master 5bcdf9848 -> f0226b37e


Advance version number to 5.4-alpha-23


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

Branch: refs/heads/master
Commit: f0226b37e630089baeaa53844268cb3eb95bf816
Parents: 66fc5f0
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Mon Sep 16 18:17:54 2013 +0100
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Mon Sep 16 18:18:18 2013 +0100

----------------------------------------------------------------------
 build.gradle | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/f0226b37/build.gradle
----------------------------------------------------------------------
diff --git a/build.gradle b/build.gradle
index 0a65e97..e101931 100755
--- a/build.gradle
+++ b/build.gradle
@@ -36,7 +36,7 @@ project.version = tapestryVersion()
 def tapestryVersion() {
 
     def major = "5.4"
-    def minor = "-alpha-22"
+    def minor = "-alpha-23"
 
     // When building on the CI server, make sure -SNAPSHOT is appended, as it is a nightly build.
     // When building normally, or for a release, no suffix is desired.


[2/2] git commit: TAP5-2184: Select component fails validation due to type mismatch when using model generated from String

Posted by hl...@apache.org.
TAP5-2184: Select component fails validation due to type mismatch when using  model generated from String


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

Branch: refs/heads/master
Commit: 66fc5f0c6310dfb0a94880f36cfd258d4174ef3e
Parents: 5bcdf98
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Mon Sep 16 17:55:40 2013 +0100
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Mon Sep 16 18:18:18 2013 +0100

----------------------------------------------------------------------
 .../tapestry5/corelib/components/Select.java    | 18 +++++++-
 .../internal/TapestryInternalUtils.java         |  4 +-
 .../tapestry5/modules/TapestryModule.java       |  2 +
 .../corelib/components/SelectTest.java          | 45 +++++++++++++++++++-
 4 files changed, 65 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/66fc5f0c/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Select.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Select.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Select.java
index 043e12c..abe41bd 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Select.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Select.java
@@ -296,12 +296,28 @@ public class Select extends AbstractField
             return false;
         }
 
+        // See TAP5-2184: Sometimes the SelectModel option values are Strings even though the
+        // submitted value (decoded by the ValueEncoder) are another type (e.g., numeric). In that case,
+        // pass each OptionModel value through the ValueEncoder for a comparison.
+        boolean alsoCompareDecodedModelValue = !(asSubmitted instanceof String);
+
         for (OptionModel om : options)
         {
-            if (om.getValue().equals(asSubmitted))
+            Object modelValue = om.getValue();
+            if (modelValue.equals(asSubmitted))
             {
                 return true;
             }
+
+            if (alsoCompareDecodedModelValue && (modelValue instanceof String))
+            {
+                Object decodedModelValue = encoder.toValue(modelValue.toString());
+
+                if (decodedModelValue.equals(asSubmitted))
+                {
+                    return true;
+                }
+            }
         }
 
         return false;

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/66fc5f0c/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java
index de17ee7..7c6e8b0 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java
@@ -16,9 +16,7 @@ package org.apache.tapestry5.internal;
 
 import org.apache.tapestry5.*;
 import org.apache.tapestry5.func.Mapper;
-import org.apache.tapestry5.internal.util.Holder;
 import org.apache.tapestry5.ioc.Messages;
-import org.apache.tapestry5.ioc.OperationTracker;
 import org.apache.tapestry5.ioc.Orderable;
 import org.apache.tapestry5.ioc.Resource;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
@@ -151,6 +149,8 @@ public class TapestryInternalUtils
 
     /**
      * Wraps the result of {@link #toOptionModels(String)} as a {@link SelectModel} (with no option groups).
+     *
+     * See TAP5-2184 for why this ends up causing some trouble!
      */
     public static SelectModel toSelectModel(String input)
     {

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/66fc5f0c/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java b/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
index adb64d8..da8043c 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
@@ -942,6 +942,8 @@ public final class TapestryModule
                     }
                 }));
 
+
+        // See TAP5-2184 for why this causes some trouble!
         configuration.add(CoercionTuple.create(String.class, SelectModel.class, new Coercion<String, SelectModel>()
         {
             public SelectModel coerce(String input)

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/66fc5f0c/tapestry-core/src/test/java/org/apache/tapestry5/corelib/components/SelectTest.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/corelib/components/SelectTest.java b/tapestry-core/src/test/java/org/apache/tapestry5/corelib/components/SelectTest.java
index 34241f0..8766775 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/corelib/components/SelectTest.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/corelib/components/SelectTest.java
@@ -26,6 +26,7 @@ import org.apache.tapestry5.internal.services.StringValueEncoder;
 import org.apache.tapestry5.internal.test.InternalBaseTestCase;
 import org.apache.tapestry5.ioc.Messages;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry5.ioc.services.TypeCoercer;
 import org.apache.tapestry5.services.Request;
 import org.apache.tapestry5.services.ValueEncoderSource;
 import org.apache.tapestry5.util.EnumSelectModel;
@@ -434,7 +435,6 @@ public class SelectTest extends InternalBaseTestCase
         ValidationTracker tracker = mockValidationTracker();
         Request request = mockRequest();
         Messages messages = mockMessages();
-        FieldValidationSupport fvs = mockFieldValidationSupport();
 
         expect(request.getParameter("xyz")).andReturn("MAC");
 
@@ -462,4 +462,47 @@ public class SelectTest extends InternalBaseTestCase
         verify();
     }
 
+    /** This a test for TAP5-2184 */
+    @Test
+    public void submitted_option_matches_against_value_encoded_option_model_value() throws ValidationException {
+        ValueEncoder<Integer> encoder = getService(ValueEncoderSource.class).getValueEncoder(Integer.class);
+
+        ValidationTracker tracker = mockValidationTracker();
+        Request request = mockRequest();
+        Messages messages = mockMessages();
+        FieldValidationSupport fvs = mockFieldValidationSupport();
+
+        expect(request.getParameter("xyz")).andReturn("5");
+
+        expect(messages.contains(EasyMock.anyObject(String.class))).andReturn(false).anyTimes();
+
+        Select select = new Select();
+
+        tracker.recordInput(select, "5");
+
+        fvs.validate(5, null, null);
+
+        replay();
+
+        // TAP5-2184 is triggered by the automatic String->SelectModel coercion, because the OptionModel
+        // values are Strings even if the desired property type is not (Integer, here). Select has a little
+        // hack to run the model values through the ValueEncoder for comparison.
+        SelectModel model = getService(TypeCoercer.class).coerce("1,5,10,20", SelectModel.class);
+
+        set(select, "encoder", encoder);
+        set(select, "model", model);
+        set(select, "request", request);
+        set(select, "secure", true);
+        set(select, "beanValidationDisabled", true); // Disable BeanValidationContextSupport
+        set(select, "tracker", tracker);
+        set(select, "fieldValidationSupport", fvs);
+
+        select.processSubmission("xyz");
+
+        verify();
+
+        assertEquals(get(select, "value"), 5);
+
+    }
+
 }


[2/2] git commit: TAP5-2184: Select component fails validation due to type mismatch when using model generated from String

Posted by hl...@apache.org.
TAP5-2184: Select component fails validation due to type mismatch when using  model generated from String


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

Branch: refs/heads/master
Commit: 66fc5f0c6310dfb0a94880f36cfd258d4174ef3e
Parents: 5bcdf98
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Mon Sep 16 17:55:40 2013 +0100
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Mon Sep 16 18:18:18 2013 +0100

----------------------------------------------------------------------
 .../tapestry5/corelib/components/Select.java    | 18 +++++++-
 .../internal/TapestryInternalUtils.java         |  4 +-
 .../tapestry5/modules/TapestryModule.java       |  2 +
 .../corelib/components/SelectTest.java          | 45 +++++++++++++++++++-
 4 files changed, 65 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/66fc5f0c/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Select.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Select.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Select.java
index 043e12c..abe41bd 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Select.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Select.java
@@ -296,12 +296,28 @@ public class Select extends AbstractField
             return false;
         }
 
+        // See TAP5-2184: Sometimes the SelectModel option values are Strings even though the
+        // submitted value (decoded by the ValueEncoder) are another type (e.g., numeric). In that case,
+        // pass each OptionModel value through the ValueEncoder for a comparison.
+        boolean alsoCompareDecodedModelValue = !(asSubmitted instanceof String);
+
         for (OptionModel om : options)
         {
-            if (om.getValue().equals(asSubmitted))
+            Object modelValue = om.getValue();
+            if (modelValue.equals(asSubmitted))
             {
                 return true;
             }
+
+            if (alsoCompareDecodedModelValue && (modelValue instanceof String))
+            {
+                Object decodedModelValue = encoder.toValue(modelValue.toString());
+
+                if (decodedModelValue.equals(asSubmitted))
+                {
+                    return true;
+                }
+            }
         }
 
         return false;

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/66fc5f0c/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java
index de17ee7..7c6e8b0 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java
@@ -16,9 +16,7 @@ package org.apache.tapestry5.internal;
 
 import org.apache.tapestry5.*;
 import org.apache.tapestry5.func.Mapper;
-import org.apache.tapestry5.internal.util.Holder;
 import org.apache.tapestry5.ioc.Messages;
-import org.apache.tapestry5.ioc.OperationTracker;
 import org.apache.tapestry5.ioc.Orderable;
 import org.apache.tapestry5.ioc.Resource;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
@@ -151,6 +149,8 @@ public class TapestryInternalUtils
 
     /**
      * Wraps the result of {@link #toOptionModels(String)} as a {@link SelectModel} (with no option groups).
+     *
+     * See TAP5-2184 for why this ends up causing some trouble!
      */
     public static SelectModel toSelectModel(String input)
     {

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/66fc5f0c/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java b/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
index adb64d8..da8043c 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
@@ -942,6 +942,8 @@ public final class TapestryModule
                     }
                 }));
 
+
+        // See TAP5-2184 for why this causes some trouble!
         configuration.add(CoercionTuple.create(String.class, SelectModel.class, new Coercion<String, SelectModel>()
         {
             public SelectModel coerce(String input)

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/66fc5f0c/tapestry-core/src/test/java/org/apache/tapestry5/corelib/components/SelectTest.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/corelib/components/SelectTest.java b/tapestry-core/src/test/java/org/apache/tapestry5/corelib/components/SelectTest.java
index 34241f0..8766775 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/corelib/components/SelectTest.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/corelib/components/SelectTest.java
@@ -26,6 +26,7 @@ import org.apache.tapestry5.internal.services.StringValueEncoder;
 import org.apache.tapestry5.internal.test.InternalBaseTestCase;
 import org.apache.tapestry5.ioc.Messages;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry5.ioc.services.TypeCoercer;
 import org.apache.tapestry5.services.Request;
 import org.apache.tapestry5.services.ValueEncoderSource;
 import org.apache.tapestry5.util.EnumSelectModel;
@@ -434,7 +435,6 @@ public class SelectTest extends InternalBaseTestCase
         ValidationTracker tracker = mockValidationTracker();
         Request request = mockRequest();
         Messages messages = mockMessages();
-        FieldValidationSupport fvs = mockFieldValidationSupport();
 
         expect(request.getParameter("xyz")).andReturn("MAC");
 
@@ -462,4 +462,47 @@ public class SelectTest extends InternalBaseTestCase
         verify();
     }
 
+    /** This a test for TAP5-2184 */
+    @Test
+    public void submitted_option_matches_against_value_encoded_option_model_value() throws ValidationException {
+        ValueEncoder<Integer> encoder = getService(ValueEncoderSource.class).getValueEncoder(Integer.class);
+
+        ValidationTracker tracker = mockValidationTracker();
+        Request request = mockRequest();
+        Messages messages = mockMessages();
+        FieldValidationSupport fvs = mockFieldValidationSupport();
+
+        expect(request.getParameter("xyz")).andReturn("5");
+
+        expect(messages.contains(EasyMock.anyObject(String.class))).andReturn(false).anyTimes();
+
+        Select select = new Select();
+
+        tracker.recordInput(select, "5");
+
+        fvs.validate(5, null, null);
+
+        replay();
+
+        // TAP5-2184 is triggered by the automatic String->SelectModel coercion, because the OptionModel
+        // values are Strings even if the desired property type is not (Integer, here). Select has a little
+        // hack to run the model values through the ValueEncoder for comparison.
+        SelectModel model = getService(TypeCoercer.class).coerce("1,5,10,20", SelectModel.class);
+
+        set(select, "encoder", encoder);
+        set(select, "model", model);
+        set(select, "request", request);
+        set(select, "secure", true);
+        set(select, "beanValidationDisabled", true); // Disable BeanValidationContextSupport
+        set(select, "tracker", tracker);
+        set(select, "fieldValidationSupport", fvs);
+
+        select.processSubmission("xyz");
+
+        verify();
+
+        assertEquals(get(select, "value"), 5);
+
+    }
+
 }