philippe::niquille | regular niche market thoughts

xajax dashboard widget integration

Dec 31st 2006
No Comments
respond
trackback

A very convenient way to implement bi-directional communication in a dashboard widget is by using XAJAX (rather than building a SOAP client or similiar in a widget-plugin). Since a widget is nothing else than a HTML, CSS and JS combination, a bit hardcoding and tweaking allows a perfect integration of XAJAX.

(1) Let’s look at the widget side:
In your main HTML widget file include xajax.js or xajax_uncompressed.js out of the xajax_js (in xajax_0.2.4). Referencing it remotely is also possible, but less efficient. Paste the $xajax->printJavascript(); output in the same file. It looks similar to the following:

/* xajax Javascript library :: version 0.2.4 */
var xajaxRequestUri=”https://your.host.com/widget_requests.php”;
var xajaxDebug=false;
var xajaxStatusMessages=false;
var xajaxWaitCursor=true;
var xajaxDefinedGet=0;
var xajaxDefinedPost=1;
var xajaxLoaded=false;
function xajax_myXAJAXfunction(){return xajax.call(”myXAJAXfunction”, arguments, 1);}

Very important is the first line setting the server side xajax response script. I try to use secure channels, of course depending on the application and the data submited.
The last line is the output of $xajax->registerFunction(”myXAJAXfunction”); and sets the function you want to call from within the widget with either a JS function or directly out of HTML events:

function myWidgetFunctionINlocalJS(myArgument) {var formdata = new Array();
formdata["one"] = myArgument;
formdata["two"] = widget.preferenceForKey(”two”);

xajax_myXAJAXfunction(formdata);

}

I use arrays to submit data to a server-side ex. PHP function over the XAJAX channel.

(2) Now we have a look at the server side response script.

$xajax = new xajax();
//$xajax->debugOn();

$xajax->outputEntitiesOn(); //automatically convert special chars

$xajax->registerFunction(”myXAJAXfunction”);
$xajax->processRequests();

function myXAJAXfunction($formdata=0) {

$user = new User;
$objResponse = new xajaxResponse();
$objResponse->addAssign(”status”,”innerHTML”, “Hello world output “.$formdata['one']);

return $objResponse;
}

It is important to include the $xajax->processRequests(); and register the same function(s) again in order for XAJAX to respond properly. Use the XAJAX response functions as you would in every other web application by assigning values and filling div’s. Don’t use $objResponse->getXML(); since it is slower and not up-version compatible.

Mandatory widget reading:

No Comments

Leave a Reply