Aaron Johnson Now with 50% less caffeine!

Posted
6 October 2006 @ 1pm

Tagged
JavaScript

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


3 Comments

Posted by
Joe Walker
7 October 2006 @ 10am

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.


Posted by
Punit gupta
6 July 2008 @ 1am

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


Posted by
Aayush
8 October 2008 @ 9am

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 Comment

Links: 10-5-2006 Links: 10-6-2006