Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Access to request parameters in DMI PRC callback

    I am making a DMI RPC call that looks something like this:

    DMI.call("myApp", "myClass", "methodToCall", myCallback, new Object[] {param});


    the execute method for myCallback I need to know the value for param that was passed in.

    I know that I could return it back from the server, but I thought there may be a cleaner way to do this since i get an RPCRequest object passed in to execute.

    Is there a way to do this?

    Thank you in advance,
    Patrick

    #2
    The typical way is to use the same pattern commonly used for event handling - if you declare the callback as an anonymous class, it can access variables from the outer scope which have been declared "final".

    Comment


      #3
      It looks like this was exactly what I needed. Thank you!

      Here is a code sample in case anyone else has to do this.

      The DMI RPC call:
      Code:
      DMI.call("myApp", "myClass", "methodToCall", getMyCallback(param), new Object[] {param});
      The callback:
      Code:
      private RPCCallback getMyCallback(String param)
      {
         final String paramNeededInCallback = param;
         return new RPCCallback()
         {
            @Override
            public void execute(RPCCallback response, Object rawData, RPCResponse)
            {
                //Handle callback.  Now param is available to you along with rawData 
                //which holds the response from the server.
            }
         };
      }

      Comment

      Working...
      X