You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by jk...@apache.org on 2015/11/05 11:12:44 UTC

tapestry-5 git commit: TAP5-2204: when checking if the model parameter is bound, access the parameter binding directly instead of the generated conduit.

Repository: tapestry-5
Updated Branches:
  refs/heads/master 376918701 -> 6a3faa357


TAP5-2204: when checking if the model parameter is bound, access the parameter binding directly instead of the generated conduit.


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

Branch: refs/heads/master
Commit: 6a3faa357009d8ae62f41d45193e48241efd9452
Parents: 3769187
Author: Jochen Kemnade <jo...@eddyson.de>
Authored: Thu Nov 5 11:10:01 2015 +0100
Committer: Jochen Kemnade <jo...@eddyson.de>
Committed: Thu Nov 5 11:10:01 2015 +0100

----------------------------------------------------------------------
 .../tapestry5/corelib/components/Select.java    | 12 ++++++--
 tapestry-core/src/test/app1/SelectDemo.tml      |  7 +++++
 .../tapestry5/integration/app1/FormTests.java   | 13 +++++++++
 .../integration/app1/pages/SelectDemo.java      | 30 ++++++++++++++++++++
 4 files changed, 60 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/6a3faa35/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 a940af5..3f5a7f4 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
@@ -18,12 +18,14 @@ import org.apache.tapestry5.corelib.base.AbstractField;
 import org.apache.tapestry5.corelib.data.BlankOption;
 import org.apache.tapestry5.corelib.data.SecureOption;
 import org.apache.tapestry5.corelib.mixins.RenderDisabled;
+import org.apache.tapestry5.internal.InternalComponentResources;
 import org.apache.tapestry5.internal.TapestryInternalUtils;
 import org.apache.tapestry5.internal.util.CaptureResultCallback;
 import org.apache.tapestry5.internal.util.SelectModelRenderer;
 import org.apache.tapestry5.ioc.Messages;
 import org.apache.tapestry5.ioc.annotations.Inject;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
+import org.apache.tapestry5.ioc.services.TypeCoercer;
 import org.apache.tapestry5.services.*;
 import org.apache.tapestry5.services.javascript.JavaScriptSupport;
 import org.apache.tapestry5.util.EnumSelectModel;
@@ -173,6 +175,9 @@ public class Select extends AbstractField
     @Inject
     private JavaScriptSupport javascriptSupport;
 
+    @Inject
+    private TypeCoercer typeCoercer;
+
     @SuppressWarnings("unused")
     @Mixin
     private RenderDisabled renderDisabled;
@@ -289,13 +294,16 @@ public class Select extends AbstractField
         }
 
         // can we skip the check for the value being in the model?
-        if (secure == SecureOption.NEVER || (secure == SecureOption.AUTO && model == null))
+
+        SelectModel selectModel = typeCoercer.coerce(((InternalComponentResources) resources)
+            .getBinding("model").get(), SelectModel.class);
+        if (secure == SecureOption.NEVER || (secure == SecureOption.AUTO && selectModel == null))
         {
             return encoder.toValue(submittedValue);
         }
 
         // for entity types the SelectModel may be unintentionally null when the form is submitted
-        if (model == null)
+        if (selectModel == null)
         {
             throw new ValidationException("Model is null when validating submitted option." +
                     " To fix: persist the SeletModel or recreate it upon form submission," +

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/6a3faa35/tapestry-core/src/test/app1/SelectDemo.tml
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/app1/SelectDemo.tml b/tapestry-core/src/test/app1/SelectDemo.tml
index 86ae7e0..60a27d4 100644
--- a/tapestry-core/src/test/app1/SelectDemo.tml
+++ b/tapestry-core/src/test/app1/SelectDemo.tml
@@ -10,6 +10,12 @@
 				model="literal:Red,Green,Blue" />
 
 		</p>
+		<p>
+			<t:label for="month" />
+			:
+			<t:select t:id="month" blankOption="always"
+				model="monthModel" secure="auto" />
+		</p>
 
 		<p>
 			<t:submit value="literal:Submit" />
@@ -17,5 +23,6 @@
 	</t:form>
 
 	<p> Selected color: ${color}</p>
+	<p> Selected month: ${month}</p>
 
 </t:border>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/6a3faa35/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java
index 32bcf0a..85a3690 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java
@@ -1251,4 +1251,17 @@ public class FormTests extends App1TestCase
 
         assertTextPresent("Validate in error");
     }
+
+    // TAP5-2204
+    @Test
+    public void select_model_with_auto_security_and_non_persistent_model() throws Exception
+    {
+        openLinks("Select Demo");
+
+        select("month", "label=August");
+
+        clickAndWait(SUBMIT);
+
+        assertTextPresent("Selected month: August");
+    }
 }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/6a3faa35/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/SelectDemo.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/SelectDemo.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/SelectDemo.java
index 518b623..00c5219 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/SelectDemo.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/SelectDemo.java
@@ -13,8 +13,12 @@
 // limitations under the License.
 package org.apache.tapestry5.integration.app1.pages;
 
+import org.apache.tapestry5.PersistenceConstants;
+import org.apache.tapestry5.SelectModel;
 import org.apache.tapestry5.annotations.Persist;
 import org.apache.tapestry5.annotations.Property;
+import org.apache.tapestry5.internal.OptionModelImpl;
+import org.apache.tapestry5.internal.SelectModelImpl;
 
 public class SelectDemo
 {
@@ -23,4 +27,30 @@ public class SelectDemo
     @Persist
     private String color;
 
+    @Property
+    @Persist
+    private String month;
+
+    @Property
+    @Persist(PersistenceConstants.FLASH)
+    private SelectModel monthModel;
+
+
+    void setupRender(){
+      monthModel = new SelectModelImpl(
+          new OptionModelImpl("January", "January"),
+          new OptionModelImpl("February", "February"),
+          new OptionModelImpl("March", "March"),
+          new OptionModelImpl("April", "April"),
+          new OptionModelImpl("May", "May"),
+          new OptionModelImpl("June", "June"),
+          new OptionModelImpl("July", "July"),
+          new OptionModelImpl("August", "August"),
+          new OptionModelImpl("Semptember", "Semptember"),
+          new OptionModelImpl("October", "October"),
+          new OptionModelImpl("November", "November"),
+          new OptionModelImpl("December", "December")
+          );
+    }
+
 }