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/27 23:41:52 UTC

git commit: Closes TAP5-1783: Autocomplete mixin should provide clientId or context. Also TAP5-2301 and TAP5-2329

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


Closes TAP5-1783: Autocomplete mixin should provide clientId or context. Also TAP5-2301 and TAP5-2329


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

Branch: refs/heads/master
Commit: 81690fe41463cd30f1404261b3394f70e6dd9fd5
Parents: d3a7a6d
Author: Thiago H. de Paula Figueiredo <th...@apache.org>
Authored: Tue May 27 18:41:32 2014 -0300
Committer: Thiago H. de Paula Figueiredo <th...@apache.org>
Committed: Tue May 27 18:41:32 2014 -0300

----------------------------------------------------------------------
 .../tapestry5/corelib/mixins/Autocomplete.java  | 34 +++++++++++++++++---
 .../src/test/app1/AutocompleteDemo.tml          |  1 +
 .../tapestry5/integration/app1/AjaxTests.java   |  3 ++
 .../app1/pages/AutocompleteDemo.java            | 32 ++++++++++++++----
 4 files changed, 59 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/81690fe4/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 bebf85d..54e55e6 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
@@ -24,6 +24,7 @@ import org.apache.tapestry5.json.JSONObject;
 import org.apache.tapestry5.services.compatibility.DeprecationWarning;
 import org.apache.tapestry5.services.javascript.JavaScriptSupport;
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
@@ -88,6 +89,20 @@ public class Autocomplete
      */
     @Parameter(defaultPrefix = BindingConstants.LITERAL)
     private String tokens;
+    
+    /**
+     * The context for the link (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 "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
+    private Object[] context;
 
     @Inject
     private DeprecationWarning deprecationWarning;
@@ -105,7 +120,7 @@ public class Autocomplete
     @Import(stylesheet="Autocomplete.css")
     void afterRender()
     {
-        Link link = resources.createEventLink(EVENT_NAME);
+        Link link = resources.createEventLink(EVENT_NAME, context);
 
         JSONObject spec = new JSONObject("id", field.getClientId(),
                 "url", link.toString()).put("minChars", minChars);
@@ -113,7 +128,7 @@ public class Autocomplete
         jsSupport.require("t5/core/autocomplete").with(spec);
     }
 
-    Object onAutocomplete(@RequestParameter("t:input")
+    Object onAutocomplete(List<String> context, @RequestParameter("t:input")
                           String input)
     {
         final Holder<List> matchesHolder = Holder.create();
@@ -134,8 +149,19 @@ public class Autocomplete
             }
         };
 
-        resources.triggerEvent(EventConstants.PROVIDE_COMPLETIONS, new Object[]
-                {input}, callback);
+        Object[] newContext;
+        if (context.size() == 0) {
+            newContext = new Object[] {input};
+        }
+        else {
+            newContext = new Object[context.size() + 1];
+            newContext[0] = input;
+            for (int i = 1; i < newContext.length; i++) {
+                newContext[i] = context.get(i - 1);
+            }
+        }
+        
+        resources.triggerEvent(EventConstants.PROVIDE_COMPLETIONS, newContext, callback);
 
         JSONObject reply = new JSONObject();
 

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/81690fe4/tapestry-core/src/test/app1/AutocompleteDemo.tml
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/app1/AutocompleteDemo.tml b/tapestry-core/src/test/app1/AutocompleteDemo.tml
index d656ab5..918ed85 100644
--- a/tapestry-core/src/test/app1/AutocompleteDemo.tml
+++ b/tapestry-core/src/test/app1/AutocompleteDemo.tml
@@ -6,6 +6,7 @@
         <t:errors/>
 
         <t:textfield t:id="title" t:mixins="autocomplete,formgroup" tokens=",;" size="60"/>
+        <t:textfield t:id="withContext" t:mixins="autocomplete,formgroup" context="context"/>
 
         <div class="form-actions">
             <input type="submit" class="btn btn-primary" value="Show Track"/>

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/81690fe4/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/AjaxTests.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/AjaxTests.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/AjaxTests.java
index 956b3fb..8293124 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/AjaxTests.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/AjaxTests.java
@@ -28,6 +28,9 @@ public class AjaxTests extends App1TestCase
 
         // And that's as far as we can go currently, because
         // of limitations in Selenium 0.8.3 and bugs in Selenium 0.9.2.
+        
+        // also test Autocomplete with context
+        
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/81690fe4/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/AutocompleteDemo.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/AutocompleteDemo.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/AutocompleteDemo.java
index 3f67a41..245a7c9 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/AutocompleteDemo.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/AutocompleteDemo.java
@@ -14,13 +14,20 @@
 
 package org.apache.tapestry5.integration.app1.pages;
 
+import org.apache.tapestry5.EventContext;
 import org.apache.tapestry5.alerts.AlertManager;
+import org.apache.tapestry5.alerts.Duration;
+import org.apache.tapestry5.alerts.Severity;
 import org.apache.tapestry5.annotations.Persist;
+import org.apache.tapestry5.annotations.Property;
 import org.apache.tapestry5.integration.app1.data.Track;
 import org.apache.tapestry5.integration.app1.services.MusicLibrary;
+import org.apache.tapestry5.ioc.annotations.AnnotationUseContext;
 import org.apache.tapestry5.ioc.annotations.Inject;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 
+import java.lang.annotation.RetentionPolicy;
+import java.util.Arrays;
 import java.util.List;
 
 public class AutocompleteDemo
@@ -29,10 +36,25 @@ public class AutocompleteDemo
     private MusicLibrary library;
 
     @Persist
+    @Property
     private String title;
 
+    @Persist
+    @Property
+    private String withContext;
+
     @Inject
     private AlertManager alertManager;
+    
+    public Object[] getContext() {
+        return new Object[] {1, RetentionPolicy.RUNTIME, AnnotationUseContext.MIXIN};
+    }
+    
+    List onProvideCompletionsFromWithContext(String partial, Integer integer,
+            RetentionPolicy retentionPolicy, AnnotationUseContext annotationUseContext) {
+        return Arrays.asList(String.format("%s : %03d, %s, %s", partial,
+                integer, retentionPolicy, annotationUseContext));
+    }
 
     List onProvideCompletionsFromTitle(String partialTitle) throws Exception
     {
@@ -59,13 +81,9 @@ public class AutocompleteDemo
         return result;
     }
 
-    public String getTitle()
-    {
-        return title;
+    void onSuccess() {
+        alertManager.alert(Duration.SINGLE, Severity.INFO, String.format("Title: %s", title));
+        alertManager.alert(Duration.SINGLE, Severity.INFO, String.format("With context: %s", withContext));
     }
 
-    public void setTitle(String title)
-    {
-        this.title = title;
-    }
 }