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

This entry was posted in JavaScript. Bookmark the permalink.

4 Responses to DWR Callback rules

  1. Joe Walker says:

    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. Punit gupta says:

    what is callback function in DWR??????

  3. Aayush says:

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

  4. Michael Rani says:

    How to get back a return value from a call back function?

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>