4 Replies Latest reply on May 30, 2006 10:44 AM by knaas

    cancelling remoting requests

      Any thoughts about JIRA issue 240?

      http://jira.jboss.com/jira/browse/JBSEAM-240

      The ajax request object does support aborting of a command. If that object could be somehow be held onto, it would be easy to do.

      For instance, Seam.Remoting.sendAjaxRequest could return the asyncReq. Then, inside of Seam.Remoting.execute, that async request could be placed into a map keyed by callId. That callId could then be returned back to the javascript client code that is invoking the remote method. If the js client wanted to cancel the request, one could call a method such as

      Seam.Remoting.cancel = function(callId)
      {
       var asyncReq = Seam.Remoting.requests.get(callId);
       Seam.Remoting.requests.remove(callId);
       if (asyncReq) {
       asyncReq.abort();
       }
      }
      


      Of course, this requests map would also need to be cleaned up when the asyncRequest finished.

      I'm sure there's probably a much better way to do this.

        • 1. Re: cancelling remoting requests
          gavin.king

          Sounds like a good idea. Shane owns this stuff.

          • 2. Re: cancelling remoting requests
            shane.bryzak

            Will look at this today.

            • 3. Re: cancelling remoting requests
              shane.bryzak

              I've checked into CVS support for cancelling a remote call. Now when you execute your remote method, you will be returned a Call object, which has the following properties:

              data - contains the call in serialized XML form
              id - the ID of the call
              callback - the callback method reference
              asyncReq - the XMLHttpRequest object

              There is also a new method, Seam.Remoting.cancelCall() which takes the call ID as a parameter. So, if you want to cancel a call that's been executed you'd do something like this:

              var myCall = Seam.Component.getInstance("myActionBean").foo();
              // Cancel the call
              Seam.Remoting.cancelCall(myCall.id);
              


              Make sure you cancel the call this way, and not via the asyncReq's abort() method. Also I haven't had time to test this stuff so let me know if there's any problems.

              • 4. Re: cancelling remoting requests

                It's working exactly as I would expect it to. Thanks for doing this so quickly!