DWR Callback rules

If you’ve spent time with DWR, you’ve probably seen both the callback function as last parameter idiom and callback function as first parameter idiom and wondered, wtf? The rules for when each one is applicable are below:

  • If there is a function first or last then this is the callback function, there is no call meta-data object and the other parameters are the Java args.
  • Otherwise, if the last param is an object with a callback member that is a function then this is call meta-data the other params are Java args.
  • Otherwise, if the first parameter is null we assume that there is no callback function and the remaining params are Java args. HOWEVER we check to see that the last param is not null and give a warning if it is.
  • Finally if the last param is null, then there is no callback function.
  • Otherwise, this is a badly formatted request – signal an error.

source: http://getahead.ltd.uk/dwr/browser/intro

4 thoughts on “DWR Callback rules”

  1. Callback as first parameter has been deprecated for a while – since 0.9 or something, and in 2.0 the option isn’t there any more.

    In the early days 0.3 to 0.9 there was no option to use an object that contained the callback and other options – you could only use a callback function. When we introduced errorHandlers and such like, the object style came in, and the last parameter way of doing things made much more sense.

    Joe.

  2. It would be nice if you can extend this post, or have another post about how to pass params to the callback method.

Leave a Reply

Your email address will not be published. Required fields are marked *