Author: mgrigorov
Date: Tue Dec 20 10:46:31 2011
New Revision: 1221193

URL: http://svn.apache.org/viewvc?rev=1221193&view=rev
Log:
WICKET-4305
Problems with AbstractAutoCompleteBehavior on BookmarkablePages

Make it possible to configure custom name of the request parameter that brings 
the user input.


Modified:
    
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java
    
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java
    
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js

Modified: 
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java?rev=1221193&r1=1221192&r2=1221193&view=diff
==============================================================================
--- 
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java
 (original)
+++ 
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java
 Tue Dec 20 10:46:31 2011
@@ -114,6 +114,7 @@ public abstract class AbstractAutoComple
                sb.append(",showListOnEmptyInput: 
").append(settings.getShowListOnEmptyInput());
                sb.append(",showListOnFocusGain: 
").append(settings.getShowListOnFocusGain());
                sb.append(",throttleDelay: 
").append(settings.getThrottleDelay());
+               sb.append(",parameterName: 
'").append(settings.getParameterName()).append('\'');
                sb.append(",showCompleteListOnFocusGain: ").append(
                        settings.getShowCompleteListOnFocusGain());
                if (settings.getCssClassName() != null)
@@ -141,9 +142,10 @@ public abstract class AbstractAutoComple
                final RequestCycle requestCycle = RequestCycle.get();
                final String val = requestCycle.getRequest()
                        .getRequestParameters()
-                       .getParameterValue("q")
+                       .getParameterValue(settings.getParameterName())
                        .toOptionalString();
 
                onRequest(val, requestCycle);
        }
+
 }

Modified: 
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java?rev=1221193&r1=1221192&r2=1221193&view=diff
==============================================================================
--- 
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java
 (original)
+++ 
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java
 Tue Dec 20 10:46:31 2011
@@ -69,6 +69,8 @@ public final class AutoCompleteSettings 
 
        private int throttleDelay = 300;
 
+       private String parameterName = "q";
+
        /**
         * Indicates whether the first item in the list is automatically 
selected when the autocomplete
         * list is shown.
@@ -334,4 +336,25 @@ public final class AutoCompleteSettings 
                this.useHideShowCoveredIEFix = useHideShowCoveredIEFix;
                return this;
        }
+
+       /**
+        * Sets the name of the request parameter that will bring the value of 
the user input
+        *
+        * @param parameterName
+        *      the name of the request parameter that will bring the value of 
the user input
+        * @return this {@link AutoCompleteSettings}
+        */
+       public AutoCompleteSettings setParameterName(final String parameterName)
+       {
+               this.parameterName = parameterName;
+               return this;
+       }
+
+       /**
+        * @return the name of the request parameter that will bring the value 
of the user input
+        */
+       public String getParameterName()
+       {
+               return parameterName;
+       }
 }

Modified: 
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js?rev=1221193&r1=1221192&r2=1221193&view=diff
==============================================================================
--- 
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js
 (original)
+++ 
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js
 Tue Dec 20 10:46:31 2011
@@ -353,32 +353,34 @@ Wicket.AutoComplete=function(elementId, 
 
     function actualUpdateChoicesShowAll()
     {
-       showIndicator();
-               
-               Wicket.Ajax.ajax({
+               showIndicator();
+
+               var paramName = cfg.parameterName;
+               var attrs = {
                        u: callbackUrl,
-                       ep: {
-                               'q': ''
-                       },
                        dt: 'html',
+                       ep: {},
                        wr: false,
                        sh: [ doUpdateChoices ]
-               });
+               };
+               attrs.ep[paramName] = '';
+               Wicket.Ajax.ajax(attrs);
     }
 
     function actualUpdateChoices()
     {
-       showIndicator();
-       var value = Wicket.$(elementId).value;
-               Wicket.Ajax.ajax({
+               showIndicator();
+               var paramName = cfg.parameterName;
+               var value = Wicket.$(elementId).value;
+               var attrs = {
                        u: callbackUrl,
-                       ep: {
-                               'q': processValue(value)
-                       },
                        wr: false,
+                       ep: {},
                        dt: 'html',
                        sh: [ doUpdateChoices ]
-               });
+               };
+           attrs.ep[paramName] = processValue(value);
+           Wicket.Ajax.ajax(attrs);
     }
     
     function showIndicator() {


Reply via email to