Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Update docs for handlers' parameters

...

Since Wicket Ajax now register DOM events (like click, change, ...) instead of using inline attributes like onclick, onchange, ... there is no more a script to decorate. Instead the new implementation provides points to listen to:

  • precondition - executed earlier. If it returns false then the Ajax call (and all handlers below) is not executed at all
  • before handler - executed before the fire of the Ajax call
  • after handler - executed after the fire of the Ajax call but before it returns ( if the Ajax call is asynchronous )then it is executed right after its firing. If it is synchronous then it is executed after the complete handler
  • success handler - executed on successful return of the Ajax call
  • failure handler - executed on unsuccessful return of the Ajax call
  • complete handler - executed on both successful and unsuccessful return

...

Code Block
  protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
  {
      super.updateAjaxAttributes(AjaxRequestAttributes attributes);

      AjaxCallListener myAjaxCallListener = new AjaxCallListener() {

        @Override public CharSequence getBeforeHandler(Component component) { return "alert('I\'m executed before the firing of the Ajax call')"; }
      };
      attributes.getAjaxCallListeners().add(myAjaxCallListener);
  }

There are also handy methods like onBefore(CharSequence), onComplete(CharSequence), ... but they do not provide access to the component which is bound with the Ajax behavior.

An Ajax request can have 0 or more IAjaxCallListener's.
o.a.w.ajax.attributes.AjaxCallListener is an adapter of IAjaxCallListener that implements all methods with noop bodies. If the body returns null or empty string then it is discarded.

...

Those replaces the old Wicket.Ajax.(registerPreCallHandler|registerPostCallHandler|registerFailureHandler) methods and uses publish/subscribe mechanism.

Example (JavaScript):

Code Block
    Wicket.Event.subscribe('/ajax/call/failure', function(jqEvent, errorThrownattributes, attributesjqXHR, jqXHRerrorThrown, textStatus) {
      // do something when an Ajax call fails
    });

...

  1. To run the Ajax tests see the description at the top of wicket-core/src/test/js/ajax.js. It is required to run them through Web Server

What parameters are passed to the handlers ?

  1. before handler - attributes (the Ajax call attributes), jqXHR (the jQuery XMLHttpRequest object), settings (the jQuery ajax settings)
  2. after handler - attributes
  3. success handler - attributes, jqXHR, data (the response), textStatus (the response status)
  4. failure handler - attributes, errorMessage (the error message from jQuery)
  5. complete handler - attrs, jqXHR, textStatus

The global listeners receive the same parameters prepended by jqEvent. This is the event triggered by jQuery. See section Global Ajax call listeners above.