Product Information > JADE Web Application Guide > Chapter 4 - Using the Rich Internet Application (RIA) Framework > Callbacks, Preprocessors, and Exception Handlers

Callbacks, Preprocessors, and Exception Handlers

For most preprocessor and callback functions, the only parameter that needs to be specified is the XML DOM tree returned by the Web service; for example:

function handleResponse(xml) { ... }

There is no requirement in JavaScript for the parameters of a function to match the number of parameters with which it is invoked, although a parameter cannot be used if it is not included in the signature.

The other parameters passed to these functions are:

With these additional parameters, the signature would be as follows.

function handleResponse(xml, InvocationArguments, cacheObject) { ... }

The InvocationArguments parameter is the parameters with which the Web service call was invoked, and is an array containing the following entries.

An easier way to pass information from the caller to the handler is to declare the handler function within the scope of the caller, as shown in the following example.

var outerVar = "abc";
Jade.Service.GetData("mydata",{cache: true, callback: function(xml){
    alert("This is the callback function.  The value of outerVar is: " +
           outerVar);
}});

This example uses an anonymous function, which is generally the easiest way to write Web service calls. In JavaScript, a function definition can be supplied where a function reference is expected. Instead of defining a function called handleResponse and specifying it by name as the callback function, you can simply define the function in-line without a name. Such anonymous functions can access all of the data that is accessible within the parent function.

If the call uses the cache, a third parameter is passed to the handler (its value is undefined if the cache is not used). The third parameter is cacheObject, which is the entry in the cache representing the data. You can store data that can be accessed during subsequent cache calls on this object. For example, when XML is received by the preprocessor function of a user, data can be extracted and changed into a more-useful format. The preprocessor adds a property to the cacheObject object, to store the data. All subsequent calls to the Web service method see the data on cacheObject and do not need to repeatedly transform the XML.

All data stored on the cacheObject object is lost if the cache entry expires or if the cache is flushed.