You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by th...@apache.org on 2014/05/28 01:03:25 UTC

git commit: Closes TAP5-2301 : Select needs a context to properly participate in AJAX pages

Repository: tapestry-5
Updated Branches:
  refs/heads/master 81690fe41 -> bb86ff40b


Closes TAP5-2301 : Select needs a context to properly participate in AJAX pages


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

Branch: refs/heads/master
Commit: bb86ff40b6e17152b65a7b4047459accf833958d
Parents: 81690fe
Author: Thiago H. de Paula Figueiredo <th...@apache.org>
Authored: Tue May 27 20:03:10 2014 -0300
Committer: Thiago H. de Paula Figueiredo <th...@apache.org>
Committed: Tue May 27 20:03:10 2014 -0300

----------------------------------------------------------------------
 .../tapestry5/corelib/components/Select.java    | 30 ++++++++++++++++----
 .../tapestry5/corelib/mixins/Autocomplete.java  |  5 ++--
 .../src/test/app1/MultiZoneUpdateInsideForm.tml |  2 +-
 .../tapestry5/integration/app1/FormTests.java   | 13 +++++++++
 .../app1/pages/MultiZoneUpdateInsideForm.java   | 16 +++++++----
 5 files changed, 52 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/bb86ff40/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 031d892..cbc2993 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
@@ -143,6 +143,19 @@ public class Select extends AbstractField
      */
     @Parameter(defaultPrefix = BindingConstants.LITERAL)
     private String zone;
+    
+    /**
+     * The context for the "valueChanged" event triggered by this component (optional parameter). 
+     * This list of values will be converted into strings and included in
+     * the URI. The strings will be coerced back to whatever their values are and made available to event handler
+     * methods. The first parameter of the context passed to "valueChanged" event handlers will
+     * still be the selected value chosen by the user, so the context passed through this parameter
+     * will be added from the second position on.
+     * 
+     * @since 5.4
+     */
+    @Parameter
+    private Object[] context;
 
     @Inject
     private FieldValidationSupport fieldValidationSupport;
@@ -230,7 +243,7 @@ public class Select extends AbstractField
         {
             javaScriptSupport.require("t5/core/select");
 
-            Link link = resources.createEventLink(CHANGE_EVENT);
+            Link link = resources.createEventLink(CHANGE_EVENT, context);
 
             writer.attributes(
                     "data-update-zone", zone,
@@ -238,15 +251,22 @@ public class Select extends AbstractField
         }
     }
 
-    Object onChange(@RequestParameter(value = "t:selectvalue", allowBlank = true)
-                    final String selectValue) throws ValidationException
+    Object onChange(final List<Context> context, 
+            @RequestParameter(value = "t:selectvalue", allowBlank = true) final String selectValue) 
+                    throws ValidationException
     {
         final Object newValue = toValue(selectValue);
 
         CaptureResultCallback<Object> callback = new CaptureResultCallback<Object>();
+        
+        Object[] newContext = new Object[context.size() + 1];
+        newContext[0] = newValue;
+        for (int i = 1; i < newContext.length; i++) {
+            newContext[i] = context.get(i - 1);
+        }
+
 
-        this.resources.triggerEvent(EventConstants.VALUE_CHANGED, new Object[]
-                {newValue}, callback);
+        this.resources.triggerEvent(EventConstants.VALUE_CHANGED, newContext, callback);
 
         this.value = newValue;
 

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/bb86ff40/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/Autocomplete.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/Autocomplete.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/Autocomplete.java
index 54e55e6..7fce141 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/Autocomplete.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/Autocomplete.java
@@ -91,14 +91,13 @@ public class Autocomplete
     private String tokens;
     
     /**
-     * The context for the link (optional parameter). This list of values will be converted into strings and included in
+     * The context for the "providecompletions" event. 
+     * This list of values will be converted into strings and included in
      * the URI. The strings will be coerced back to whatever their values are and made available to event handler
      * methods. The first parameter of the context passed to "providecompletions" event handlers will
      * still be the partial string typed by the user, so the context passed through this parameter
      * will be added from the second position on.
      * 
-     * Paramenter introduced in 5.4
-     * 
      * @since 5.4
      */
     @Parameter

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/bb86ff40/tapestry-core/src/test/app1/MultiZoneUpdateInsideForm.tml
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/app1/MultiZoneUpdateInsideForm.tml b/tapestry-core/src/test/app1/MultiZoneUpdateInsideForm.tml
index 9ae3469..ca3180e 100644
--- a/tapestry-core/src/test/app1/MultiZoneUpdateInsideForm.tml
+++ b/tapestry-core/src/test/app1/MultiZoneUpdateInsideForm.tml
@@ -4,7 +4,7 @@
 
   <form t:type="Form" t:id="form" t:clientValidation="none" action="#">
     <t:label for="selectValue1"/>
-    <select t:type="Select" t:id="selectValue1" t:validate="required" t:zone="select1ValueZone"/>
+    <select t:type="Select" t:id="selectValue1" t:validate="required" t:zone="select1ValueZone" t:context="selectContext"/>
     <t:zone t:id="select1ValueZone" visible="false">Show</t:zone>
     <t:zone t:id="select2ValueZone">
       <t:label for="selectValue2"/>

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/bb86ff40/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 9df7a1c..5e997f3 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
@@ -1189,5 +1189,18 @@ public class FormTests extends App1TestCase
         }
         
     }
+    
+    /** TAP5-2301 */
+    @Test
+    public void select_context() {
+        
+        openLinks("MultiZone Update inside a Form");
+        selenium.select("selectValue1", "label=3 pre ajax");
+        waitForAjaxRequestsToComplete();
+        assertEquals(
+                "4 post ajax, number 013, retention policy RUNTIME",
+                selenium.getText("//select[@id='selectValue2']/option"));
+        
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/bb86ff40/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/MultiZoneUpdateInsideForm.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/MultiZoneUpdateInsideForm.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/MultiZoneUpdateInsideForm.java
index 21c53a9..ceccda0 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/MultiZoneUpdateInsideForm.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/MultiZoneUpdateInsideForm.java
@@ -14,6 +14,7 @@
 
 package org.apache.tapestry5.integration.app1.pages;
 
+import java.lang.annotation.RetentionPolicy;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -65,6 +66,10 @@ public class MultiZoneUpdateInsideForm
 
     @Component(id = "select2ValueZone")
     private Zone select2ValueZone;
+    
+    public Object[] getSelectContext() {
+        return new Object[] {13, RetentionPolicy.RUNTIME};
+    }
 
     public class SelectObj
     {
@@ -163,13 +168,14 @@ public class MultiZoneUpdateInsideForm
     }
 
     @Log
-    public Object onValueChangedFromSelectValue1(SelectObj selectObj)
+    public Object onValueChangedFromSelectValue1(SelectObj selectObj, Integer integer, RetentionPolicy retentionPolicy)
     {
+        final String suffix = String.format(", number %03d, retention policy %s", integer, retentionPolicy);
         List<SelectObj> select2List = new ArrayList();
-        select2List.add(new SelectObj(4, "4 post ajax"));
-        select2List.add(new SelectObj(5, "5 post ajax"));
-        select2List.add(new SelectObj(6, "6 post ajax"));
-        select2List.add(new SelectObj(7, "7 post ajax"));
+        select2List.add(new SelectObj(4, "4 post ajax" + suffix));
+        select2List.add(new SelectObj(5, "5 post ajax" + suffix));
+        select2List.add(new SelectObj(6, "6 post ajax" + suffix));
+        select2List.add(new SelectObj(7, "7 post ajax" + suffix));
         select2Model = new SelectObjModel(select2List);
 
         if (request.isXHR())