Wicket
  1. Wicket
  2. WICKET-4122

Event listener not properly detached for multipart AJAX requests

    Details

      Description

      We are using HtmlUnit for functional testing of a wicket application. We have several issues with it but one of the more critical problems arises whenever a multipart form is submitted via AJAX. Internally wicket apparently uses an iframe to submit the request and listens for the "load" event of this iframe to detect the success of the request.

      The problem is that HtmlUnit fires the "load" event twice. I am not sure if this is a HtmlUnit problem (I do suspect that it is), but when looking at the wicket code I am wondering about these lines of javascript code:

      Here in wicket-ajax.js:1215 the event is attached

      Wicket.Event.add(iframe, "load", this.handleMultipartComplete.bind(this));

      And later in wicket-ajax.js:1246 it is detached

      // remove the event
      if (iframe.detachEvent)
      iframe.detachEvent("onload", this.handleMultipartComplete);
      else
      iframe.removeEventListener("load", this.handleMultipartComplete, false);

      But because the bind function returns a new object this should never work, right? I have attached a patch that fixes the problem in my environment, please take a look at it if this makes sense.

        Activity

        Andreas Kappler created issue -
        Andreas Kappler made changes -
        Field Original Value New Value
        Description We are using HtmlUnit for functional testing of a wicket application. We have several issues with it but one of the more critical problems arises whenever a multipart form is submitted via AJAX. Internally wicket apparently uses an iframe to submit the request and listens for the "load" event of this iframe to detect the success of the request.

        The problem is that HtmlUnit fires the "load" event twice. I am not sure if this is a HtmlUnit problem (I do suspect that it is), but when looking at the wicket code I am wondering about these lines of javascript code:

        Here in wicket-ajax.js:1215 the event is attached
        {code:javascript}
        Wicket.Event.add(iframe, "load", this.handleMultipartComplete.bind(this));
        {code}

        And later in wicket-ajax.js:1246 it is detached
        {code:javascript}
        // remove the event
        if (iframe.detachEvent)
        iframe.detachEvent("onload", this.handleMultipartComplete);
        else
        iframe.removeEventListener("load", this.handleMultipartComplete, false);
        {code}

        But because the bind function returns a new object this should never work, right? I have attached a patch that fixes the problem in my environment, please take a look at it if this makes sense.

        We are using HtmlUnit for functional testing of a wicket application. We have several issues with it but one of the more critical problems arises whenever a multipart form is submitted via AJAX. Internally wicket apparently uses an iframe to submit the request and listens for the "load" event of this iframe to detect the success of the request.

        The problem is that HtmlUnit fires the "load" event twice. I am not sure if this is a HtmlUnit problem (I do suspect that it is), but when looking at the wicket code I am wondering about these lines of javascript code:

        Here in wicket-ajax.js:1215 the event is attached

         Wicket.Event.add(iframe, "load", this.handleMultipartComplete.bind(this));


        And later in wicket-ajax.js:1246 it is detached

         // remove the event
         if (iframe.detachEvent)
          iframe.detachEvent("onload", this.handleMultipartComplete);
         else
          iframe.removeEventListener("load", this.handleMultipartComplete, false);

        But because the bind function returns a new object this should never work, right? I have attached a patch that fixes the problem in my environment, please take a look at it if this makes sense.

        Andreas Kappler made changes -
        Attachment wicket-ajax-patch.patch [ 12498599 ]
        Igor Vaynberg made changes -
        Assignee Martin Grigorov [ mgrigorov ]
        Martin Grigorov made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 1.5.2 [ 12318078 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Martin Grigorov
            Reporter:
            Andreas Kappler
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development