Updated Branches:
  refs/heads/master 3447534c3 -> fe0bcdb0b

WICKET-3367
Rewrite all JavaScript inline event handlers to be proper attached event 
handlers

Replace 
AjaxRequestAttributes.get(Before|After|Success|Failure|Complete)Handlers() with 
AjaxRequestAttributes.getAjaxCallListeners().
IAjaxCallListener is similar to old IAjaxCallDecorator but it doesn't decorate 
(because there is no script to decorate anymore) and have few more methods


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

Branch: refs/heads/master
Commit: fe0bcdb0b67d991f1f05a88e639623a2331faf9d
Parents: 3447534
Author: martin-g <[email protected]>
Authored: Tue Jan 3 12:09:50 2012 +0200
Committer: martin-g <[email protected]>
Committed: Tue Jan 3 12:09:50 2012 +0200

----------------------------------------------------------------------
 .../wicket/ajax/AbstractDefaultAjaxBehavior.java   |   99 +++++--------
 .../org/apache/wicket/ajax/IAjaxCallDecorator.java |    2 +-
 .../wicket/ajax/attributes/AjaxCallListener.java   |   57 ++++++++
 .../ajax/attributes/AjaxRequestAttributes.java     |  110 +--------------
 .../wicket/ajax/attributes/IAjaxCallListener.java  |   76 ++++++++++
 .../ajax/attributes/JavaScriptFunctionBody.java    |    3 +-
 .../wicket/examples/ajax/builtin/LinksPage.java    |   61 ++++++--
 .../captcha/kittens/KittenCaptchaPanel.java        |   42 +++---
 8 files changed, 252 insertions(+), 198 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/fe0bcdb0/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java
 
b/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java
index d868940..832248a 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java
@@ -20,11 +20,8 @@ import org.apache.wicket.Component;
 import org.apache.wicket.Page;
 import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
 import org.apache.wicket.ajax.attributes.AjaxRequestAttributes.Method;
-import org.apache.wicket.ajax.attributes.JavaScriptAfterHandler;
-import org.apache.wicket.ajax.attributes.JavaScriptBeforeHandler;
-import org.apache.wicket.ajax.attributes.JavaScriptFailureHandler;
+import org.apache.wicket.ajax.attributes.IAjaxCallListener;
 import org.apache.wicket.ajax.attributes.JavaScriptPrecondition;
-import org.apache.wicket.ajax.attributes.JavaScriptSuccessHandler;
 import org.apache.wicket.ajax.json.JSONException;
 import org.apache.wicket.ajax.json.JSONObject;
 import org.apache.wicket.behavior.AbstractAjaxBehavior;
@@ -111,24 +108,13 @@ public abstract class AbstractDefaultAjaxBehavior extends 
AbstractAjaxBehavior
 
                AjaxRequestAttributes attributes = getAttributes();
 
-               List<JavaScriptBeforeHandler> beforeHandlers = 
attributes.getBeforeHandlers();
-               for (JavaScriptBeforeHandler beforeHandler : beforeHandlers) {
-                       beforeHandler.renderHead(component, response);
-               }
-
-               List<JavaScriptAfterHandler> afterHandlers = 
attributes.getAfterHandlers();
-               for (JavaScriptAfterHandler afterHandler : afterHandlers) {
-                       afterHandler.renderHead(component, response);
-               }
-
-               List<JavaScriptFailureHandler> failureHandlers = 
attributes.getFailureHandlers();
-               for (JavaScriptFailureHandler failureHandler : failureHandlers) 
{
-                       failureHandler.renderHead(component, response);
-               }
-
-               List<JavaScriptSuccessHandler> successHandlers = 
attributes.getSuccessHandlers();
-               for (JavaScriptSuccessHandler successHandler : successHandlers) 
{
-                       successHandler.renderHead(component, response);
+               List<IAjaxCallListener> ajaxCallListeners = 
attributes.getAjaxCallListeners();
+               for (IAjaxCallListener ajaxCallListener : ajaxCallListeners) {
+                       if (ajaxCallListener instanceof 
IComponentAwareHeaderContributor)
+                       {
+                               IComponentAwareHeaderContributor contributor = 
(IComponentAwareHeaderContributor) ajaxCallListener;
+                               contributor.renderHead(component, response);
+                       }
                }
 
                List<JavaScriptPrecondition> preconditions = 
attributes.getPreconditions();
@@ -166,28 +152,6 @@ public abstract class AbstractDefaultAjaxBehavior extends 
AbstractAjaxBehavior
         */
        private void 
updateAjaxAttributesBackwardCompatibility(AjaxRequestAttributes attributes)
        {
-               IAjaxCallDecorator callDecorator = getAjaxCallDecorator();
-               if (callDecorator != null)
-               {
-                       CharSequence onSuccessScript = 
callDecorator.decorateOnSuccessScript(getComponent(),
-                               getSuccessScript());
-
-                       if (onSuccessScript != null)
-                       {
-                               JavaScriptSuccessHandler successHandler = new 
JavaScriptSuccessHandler(onSuccessScript);
-                               
attributes.getSuccessHandlers().add(successHandler);
-                       }
-
-                       CharSequence onFailureScript = 
callDecorator.decorateOnFailureScript(getComponent(),
-                               getFailureScript());
-
-                       if (onFailureScript != null)
-                       {
-                               JavaScriptFailureHandler failureHandler = new 
JavaScriptFailureHandler(onFailureScript);
-                               
attributes.getFailureHandlers().add(failureHandler);
-                       }
-               }
-
                CharSequence preconditionScript = getPreconditionScript();
                if (preconditionScript != null)
                {
@@ -280,24 +244,37 @@ public abstract class AbstractDefaultAjaxBehavior extends 
AbstractAjaxBehavior
                                attributesJson.put("i", indicatorId);
                        }
 
-                       for (JavaScriptBeforeHandler bh : 
attributes.getBeforeHandlers())
+                       for (IAjaxCallListener ajaxCallListener : 
attributes.getAjaxCallListeners())
                        {
-                               attributesJson.append("bh", bh);
-                       }
+                               CharSequence beforeHandler = 
ajaxCallListener.getBeforeHandler(component);
+                               if (Strings.isEmpty(beforeHandler) == false)
+                               {
+                                       attributesJson.append("bh", 
beforeHandler);
+                               }
 
-                       for (JavaScriptAfterHandler ah : 
attributes.getAfterHandlers())
-                       {
-                               attributesJson.append("ah", ah);
-                       }
+                               CharSequence afterHandler = 
ajaxCallListener.getAfterHandler(component);
+                               if (Strings.isEmpty(afterHandler) == false)
+                               {
+                                       attributesJson.append("ah", 
afterHandler);
+                               }
 
-                       for (JavaScriptSuccessHandler sh : 
attributes.getSuccessHandlers())
-                       {
-                               attributesJson.append("sh", sh);
-                       }
+                               CharSequence successHandler = 
ajaxCallListener.getSuccessHandler(component);
+                               if (Strings.isEmpty(successHandler) == false)
+                               {
+                                       attributesJson.append("sh", 
successHandler);
+                               }
 
-                       for (JavaScriptFailureHandler fh : 
attributes.getFailureHandlers())
-                       {
-                               attributesJson.append("fh", fh);
+                               CharSequence failureHandler = 
ajaxCallListener.getFailureHandler(component);
+                               if (Strings.isEmpty(failureHandler) == false)
+                               {
+                                       attributesJson.append("fh", 
failureHandler);
+                               }
+
+                               CharSequence completeHandler = 
ajaxCallListener.getCompleteHandler(component);
+                               if (Strings.isEmpty(completeHandler) == false)
+                               {
+                                       attributesJson.append("ch", 
completeHandler);
+                               }
                        }
 
                        for (JavaScriptPrecondition pre : 
attributes.getPreconditions())

http://git-wip-us.apache.org/repos/asf/wicket/blob/fe0bcdb0/wicket-core/src/main/java/org/apache/wicket/ajax/IAjaxCallDecorator.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/ajax/IAjaxCallDecorator.java 
b/wicket-core/src/main/java/org/apache/wicket/ajax/IAjaxCallDecorator.java
index 3c0cda3..bc34934 100644
--- a/wicket-core/src/main/java/org/apache/wicket/ajax/IAjaxCallDecorator.java
+++ b/wicket-core/src/main/java/org/apache/wicket/ajax/IAjaxCallDecorator.java
@@ -61,7 +61,7 @@ import org.apache.wicket.markup.html.IHeaderContributor;
  * @since 1.2
  * 
  * @author Igor Vaynberg (ivaynberg)
- * @deprecated Use AjaxRequestAttributes instead.
+ * @deprecated Use IAjaxCallListener instead.
  */
 @Deprecated
 public interface IAjaxCallDecorator extends IClusterable

http://git-wip-us.apache.org/repos/asf/wicket/blob/fe0bcdb0/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxCallListener.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxCallListener.java
 
b/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxCallListener.java
new file mode 100644
index 0000000..d98bf6f
--- /dev/null
+++ 
b/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxCallListener.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.ajax.attributes;
+
+import org.apache.wicket.Component;
+
+/**
+ * An adapter for implementations of IAjaxCallListener.
+ *
+ * @since 6.0
+ */
+public class AjaxCallListener implements IAjaxCallListener
+{
+       @Override
+       public CharSequence getSuccessHandler(Component component)
+       {
+               return null;
+       }
+
+       @Override
+       public CharSequence getFailureHandler(Component component)
+       {
+               return null;
+       }
+
+       @Override
+       public CharSequence getBeforeHandler(Component component)
+       {
+               return null;
+       }
+
+       @Override
+       public CharSequence getAfterHandler(Component component)
+       {
+               return null;
+       }
+
+       @Override
+       public CharSequence getCompleteHandler(Component component)
+       {
+               return null;
+       }
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/fe0bcdb0/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxRequestAttributes.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxRequestAttributes.java
 
b/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxRequestAttributes.java
index d3f0454..d9cb625 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxRequestAttributes.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxRequestAttributes.java
@@ -82,11 +82,8 @@ public final class AjaxRequestAttributes
 
        private String dataType = XML_DATA_TYPE;
 
+       private List<IAjaxCallListener> ajaxCallListeners = null;
        private List<JavaScriptPrecondition> preconditions = null;
-       private List<JavaScriptBeforeHandler> beforeHandlers = null;
-       private List<JavaScriptAfterHandler> afterHandlers = null;
-       private List<JavaScriptSuccessHandler> successHandlers = null;
-       private List<JavaScriptFailureHandler> failureHandlers = null;
        private Map<String, Object> extraParameters = null;
        private List<CharSequence> dynamicExtraParameters = null;
        private AjaxChannel channel = null;
@@ -238,109 +235,16 @@ public final class AjaxRequestAttributes
        }
 
        /**
-        * Array of javascript functions that are invoked before the actual 
AJAX request. This
-        * invocation only happens when all precondition functions return true. 
Each of the function
-        * will get a <code>RequestQueueItem</code> instance passed as first 
argument.
-        * <p>
-        * Example of single function:
-        * 
-        * <pre>
-        *    function(requestQueueItem) 
-        *    { 
-        *      doSomethingWhenAjaxRequestBegins();
-        *    }
-        * </pre>
-        * 
-        * @see #getPreconditions()
-        * 
-        * @return List<JavaScriptBeforeHandler>
-        */
-       public List<JavaScriptBeforeHandler> getBeforeHandlers()
-       {
-               if (beforeHandlers == null)
-               {
-                       beforeHandlers = new 
ArrayList<JavaScriptBeforeHandler>();
-               }
-               return beforeHandlers;
-       }
-
-       /**
-        * Array of JavaScript functions that are invoked after the AJAX 
request if fired. This
-        * invocation only happens when all precondition functions return true.
-        * <p>
-        * Example of single function:
-        * 
-        * <pre>
-        * function()
-        * {
-        *      doSomethingWhenAjaxRequestIsFired();
-        * }
-        * </pre>
-        * 
-        * @see #getPreconditions()
-        * 
-        * @return List<JavaScriptAfterHandler>
-        */
-       public List<JavaScriptAfterHandler> getAfterHandlers()
-       {
-               if (afterHandlers == null)
-               {
-                       afterHandlers = new ArrayList<JavaScriptAfterHandler>();
-               }
-               return afterHandlers;
-       }
-
-       /**
-        * Array of javascript functions that are invoked after the request is 
successfully processed.
-        * Each function will get a <code>RequestQueueItem</code> instance 
passed as fist argument.
-        * <p>
-        * Example of single function:
-        * 
-        * <pre>
-        *    function(requestQueueItem) 
-        *    { 
-        *      doSomethingWhenRequestIsSuccessfullyProcessed();
-        *    }
-        * </pre>
-        * 
-        * @return List<JavaScriptSuccessHandler>
-        */
-       public List<JavaScriptSuccessHandler> getSuccessHandlers()
-       {
-               if (successHandlers == null)
-               {
-                       successHandlers = new 
ArrayList<JavaScriptSuccessHandler>();
-               }
-               return successHandlers;
-       }
-
-       /**
-        * Array of javascript functions that are invoked when an unexpected 
error happens during the
-        * AJAX request or the processing afterwards, or when some of the 
timeouts is exceeded. The
-        * functions will get a <code>RequestQueueItem</code> passed as fist 
argument. If possible error
-        * message will be second argument passed to the handlers.
-        * <p>
-        * Example of single function:
-        * 
-        * <pre>
-        *    function(requestQueueItem, error) 
-        *    { 
-        *      if (typeof(error) == &quot;string&quot;) 
-        *      {
-        *              alert('Error processing request ' + error);
-        *      }
-        *    }
-        * </pre>
-        * 
-        * @return List<JavaScriptFailureHandler>
+        *
+        * @return List<IAjaxCallListener>
         */
-       public List<JavaScriptFailureHandler> getFailureHandlers()
+       public List<IAjaxCallListener> getAjaxCallListeners()
        {
-               if (failureHandlers == null)
+               if (ajaxCallListeners == null)
                {
-                       failureHandlers = new 
ArrayList<JavaScriptFailureHandler>();
+                       ajaxCallListeners = new ArrayList<IAjaxCallListener>();
                }
-               return failureHandlers;
+               return ajaxCallListeners;
        }
 
        /**

http://git-wip-us.apache.org/repos/asf/wicket/blob/fe0bcdb0/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/IAjaxCallListener.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/IAjaxCallListener.java
 
b/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/IAjaxCallListener.java
new file mode 100644
index 0000000..f1f6245
--- /dev/null
+++ 
b/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/IAjaxCallListener.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.ajax.attributes;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.IClusterable;
+
+/**
+ * Interface used to listen at the most important points when Wicket performs 
an Ajax callback.
+ * <br/>
+ *  Ajax call listeners are potential contributors to the page header by 
implementing
+ * {@link org.apache.wicket.markup.html.IComponentAwareHeaderContributor}. 
E.g. the JavaScript used
+ * by the listener may depend on some JavaScript library, by implementing
+ * {@link org.apache.wicket.markup.html.IComponentAwareHeaderContributor} 
interface
+ * they can assure it will be loaded.
+ *
+ * @since 6.0
+ */
+public interface IAjaxCallListener extends IClusterable
+{
+       /**
+        * @param component
+        *      the Component with the Ajax behavior
+        * @return the JavaScript that will be executed after a successful
+        *      return of the Ajax call.
+        */
+       CharSequence getSuccessHandler(Component component);
+
+       /**
+        * @param component
+        *      the Component with the Ajax behavior
+        * @return the JavaScript that will be executed after a unsuccessful
+        *      return of the Ajax call.
+        */
+       CharSequence getFailureHandler(Component component);
+
+       /**
+        * @param component
+        *      the Component with the Ajax behavior
+        * @return the JavaScript that will be executed before the Ajax call.
+        */
+       CharSequence getBeforeHandler(Component component);
+
+       /**
+        * @param component
+        *      the Component with the Ajax behavior
+        * @return the JavaScript that will be executed after the start of the 
Ajax call
+        *      but before its response is returned. <strong>Note</strong>: if 
the Ajax call
+        *      is synchronous (see {@link 
AjaxRequestAttributes#setAsynchronous(boolean)})
+        *      then this JavaScript will be executed after the
+        *      {@linkplain #getCompleteHandler(org.apache.wicket.Component) 
complete handler}.
+        */
+       CharSequence getAfterHandler(Component component);
+
+       /**
+        * @param component
+        *      the Component with the Ajax behavior
+        * @return the JavaScript that will be executed after both successful
+        *      and unsuccessful return of the Ajax call.
+        */
+       CharSequence getCompleteHandler(Component component);
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/fe0bcdb0/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/JavaScriptFunctionBody.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/JavaScriptFunctionBody.java
 
b/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/JavaScriptFunctionBody.java
index b5b54cd..908677b 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/JavaScriptFunctionBody.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/JavaScriptFunctionBody.java
@@ -17,6 +17,7 @@
 package org.apache.wicket.ajax.attributes;
 
 import org.apache.wicket.Component;
+import org.apache.wicket.IClusterable;
 import org.apache.wicket.markup.head.IHeaderResponse;
 import org.apache.wicket.markup.html.IComponentAwareHeaderContributor;
 
@@ -26,7 +27,7 @@ import 
org.apache.wicket.markup.html.IComponentAwareHeaderContributor;
  * Such classes can contribute to the header response by overriding 
#renderHead(Component, IHeaderResponse)
  * method.
  */
-public class JavaScriptFunctionBody implements IComponentAwareHeaderContributor
+public class JavaScriptFunctionBody implements 
IComponentAwareHeaderContributor, IClusterable
 {
        private final CharSequence functionBody;
 

http://git-wip-us.apache.org/repos/asf/wicket/blob/fe0bcdb0/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/LinksPage.java
----------------------------------------------------------------------
diff --git 
a/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/LinksPage.java
 
b/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/LinksPage.java
index d97f97a..97e9c5e 100644
--- 
a/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/LinksPage.java
+++ 
b/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/LinksPage.java
@@ -16,14 +16,12 @@
  */
 package org.apache.wicket.examples.ajax.builtin;
 
-import java.util.List;
-
+import org.apache.wicket.Component;
 import org.apache.wicket.WicketRuntimeException;
-import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
 import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.attributes.JavaScriptBeforeHandler;
-import org.apache.wicket.ajax.attributes.JavaScriptFailureHandler;
-import org.apache.wicket.ajax.attributes.JavaScriptSuccessHandler;
+import org.apache.wicket.ajax.attributes.AjaxCallListener;
+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
+import org.apache.wicket.ajax.attributes.IAjaxCallListener;
 import org.apache.wicket.ajax.markup.html.AjaxFallbackLink;
 import org.apache.wicket.ajax.markup.html.AjaxLink;
 import org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink;
@@ -31,6 +29,8 @@ import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.model.PropertyModel;
 import org.apache.wicket.settings.IExceptionSettings.AjaxErrorStrategy;
 
+import java.util.List;
+
 
 /**
  * Ajax links demo.
@@ -142,10 +142,26 @@ public class LinksPage extends BasePage
                        {
                                super.updateAjaxAttributes(attributes);
 
-                               attributes.getBeforeHandlers().add(new 
JavaScriptBeforeHandler("alert('Before ajax call');"));
-                               attributes.getSuccessHandlers().add(new 
JavaScriptSuccessHandler("alert('Success');"));
-// attributes.getSuccessHandlers().add("alert('Success2');");
-                               attributes.getFailureHandlers().add(new 
JavaScriptFailureHandler("alert('Failure');"));
+                               IAjaxCallListener ajaxCallListener = new 
AjaxCallListener() {
+                                       @Override
+                                       public CharSequence 
getSuccessHandler(Component component)
+                                       {
+                                               return "alert('Success');";
+                                       }
+
+                                       @Override
+                                       public CharSequence 
getBeforeHandler(Component component)
+                                       {
+                                               return "alert('Before ajax 
call');";
+                                       }
+
+                                       @Override
+                                       public CharSequence 
getFailureHandler(Component component)
+                                       {
+                                               return "alert('Failure');";
+                                       }
+                               };
+                               
attributes.getAjaxCallListeners().add(ajaxCallListener);
 
                                List<CharSequence> urlArgumentMethods = 
attributes.getDynamicExtraParameters();
                                urlArgumentMethods.add("return {'htmlname': 
document.documentElement.tagName};");
@@ -173,10 +189,27 @@ public class LinksPage extends BasePage
                        protected void 
updateAjaxAttributes(AjaxRequestAttributes attributes)
                        {
                                super.updateAjaxAttributes(attributes);
-
-                               attributes.getBeforeHandlers().add(new 
JavaScriptBeforeHandler("alert('Before ajax call');"));
-                               attributes.getSuccessHandlers().add(new 
JavaScriptSuccessHandler("alert('Success');"));
-                               attributes.getFailureHandlers().add(new 
JavaScriptFailureHandler("alert('Failure');"));
+                               
+                               IAjaxCallListener ajaxCallListener = new 
AjaxCallListener() {
+                                       @Override
+                                       public CharSequence 
getBeforeHandler(Component component)
+                                       {
+                                               return "alert('Before ajax 
call');";
+                                       }
+
+                                       @Override
+                                       public CharSequence 
getSuccessHandler(Component component)
+                                       {
+                                               return "alert('Success');";
+                                       }
+
+                                       @Override
+                                       public CharSequence 
getFailureHandler(Component component)
+                                       {
+                                               return "alert('Failure');";
+                                       }
+                               };
+                               
attributes.getAjaxCallListeners().add(ajaxCallListener);
                        }
                });
 

http://git-wip-us.apache.org/repos/asf/wicket/blob/fe0bcdb0/wicket-extensions/src/main/java/org/apache/wicket/extensions/captcha/kittens/KittenCaptchaPanel.java
----------------------------------------------------------------------
diff --git 
a/wicket-extensions/src/main/java/org/apache/wicket/extensions/captcha/kittens/KittenCaptchaPanel.java
 
b/wicket-extensions/src/main/java/org/apache/wicket/extensions/captcha/kittens/KittenCaptchaPanel.java
index 500aae0..bac0212 100644
--- 
a/wicket-extensions/src/main/java/org/apache/wicket/extensions/captcha/kittens/KittenCaptchaPanel.java
+++ 
b/wicket-extensions/src/main/java/org/apache/wicket/extensions/captcha/kittens/KittenCaptchaPanel.java
@@ -16,27 +16,13 @@
  */
 package org.apache.wicket.extensions.captcha.kittens;
 
-import java.awt.Dimension;
-import java.awt.Graphics2D;
-import java.awt.Point;
-import java.awt.image.BufferedImage;
-import java.awt.image.RescaleOp;
-import java.io.IOException;
-import java.io.Serializable;
-import java.lang.ref.SoftReference;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Random;
-
-import javax.imageio.ImageIO;
-import javax.imageio.stream.MemoryCacheImageInputStream;
-
+import org.apache.wicket.Component;
 import org.apache.wicket.IResourceListener;
 import org.apache.wicket.ajax.AjaxEventBehavior;
 import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.attributes.AjaxCallListener;
 import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
-import org.apache.wicket.ajax.attributes.JavaScriptBeforeHandler;
+import org.apache.wicket.ajax.attributes.IAjaxCallListener;
 import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.markup.html.image.Image;
 import org.apache.wicket.markup.html.image.NonCachingImage;
@@ -48,6 +34,19 @@ import org.apache.wicket.request.http.WebResponse;
 import org.apache.wicket.request.resource.DynamicImageResource;
 import org.apache.wicket.util.time.Time;
 
+import javax.imageio.ImageIO;
+import javax.imageio.stream.MemoryCacheImageInputStream;
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.awt.image.RescaleOp;
+import java.io.IOException;
+import java.io.Serializable;
+import java.lang.ref.SoftReference;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Random;
+
 /**
  * A unique and fun-to-use captcha technique I developed at Thoof.
  * 
@@ -169,7 +168,14 @@ public class KittenCaptchaPanel extends Panel
                        protected void 
updateAjaxAttributes(AjaxRequestAttributes attributes)
                        {
                                super.updateAjaxAttributes(attributes);
-                               attributes.getBeforeHandlers().add(new 
JavaScriptBeforeHandler("showLoadingIndicator();"));
+                               IAjaxCallListener ajaxCallListener = new 
AjaxCallListener() {
+                                       @Override
+                                       public CharSequence 
getBeforeHandler(Component component)
+                                       {
+                                               return 
"showLoadingIndicator();";
+                                       }
+                               };
+                               
attributes.getAjaxCallListeners().add(ajaxCallListener);
                                List<CharSequence> dynamicExtraParameters = 
attributes.getDynamicExtraParameters();
                                dynamicExtraParameters.add("return { x: 
getEventX(this, event), y: getEventY(this, event)}");
                        }

Reply via email to