Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-2739

Throttling breaks AjaxFormSubmitBehavior's precondition check

    XMLWordPrintableJSON

Details

    Description

      AjaxFormSubmitBehavior#getPreconditionScript() looks like:
      return "return Wicket.$$(this)&&Wicket.$$('" + getForm().getMarkupId() + "')";

      The javascript keyword 'this' should point to the DOM element which initiated the ajax event. (It wants to check that the component still exists on the page, before initiating the ajax request, as well as the form this behavior is linked to). When using an AjaxThrottlingCallDecorator to throttle the ajax request, the throttle callback function is not bound to the DOM element. The result is that 'this' refers to the window element, in the context of the throttle callback. The precondition function gets bind(this) called on it, but it's the wrong 'this'. I think that the throttle callback should be bound to 'this' at the time the callback is defined.

      AbstractDefaultAjaxBehavior#throttleScript(...) should be changed from:

      return new AppendingStringBuffer("wicketThrottler.throttle( '").append(throttleId)
      .append("', ")
      .append(throttleDelay.getMilliseconds())
      .append(", function()

      { ") .append(script) .append("});");
      to:
      return new AppendingStringBuffer("wicketThrottler.throttle( '").append(throttleId)
      .append("', ")
      .append(throttleDelay.getMilliseconds())
      .append(", function() { ") .append(script) .append("}

      .bind(this));");

      Attachments

        1. throttleBreaksPrecondition.zip
          16 kB
          Russell Morrisey

        Activity

          People

            ivaynberg Igor Vaynberg
            rmorrisey Russell Morrisey
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: