0.5 beta 3 Release Notes






0.5 beta 3 Release Notes

Contents

[edit] Updated plugin support

Plugins can now have more control over the output generated by xajax. A plugin can now output javascript and style information to the head of the document being generated using a new function generateClientScript.

Also, request plugins do not replace the existing xajax request functionality, but instead they add to it. New plugins can be written to support function registration, client script generation as well as request processing services.

[edit] Server side event registration and handling

Using the new plugin support (discussed above), a new plugin has been created which handles the registration of events and event handlers on the server side. Now a series of event handler functions can be attached to a single event. The event can be triggered in a manner similar to calling a registered function.

$requestTriggerEvent_EventName = $xajax->register(XAJAX_EVENT, 'eventName');
$xajax->register(XAJAX_EVENT_HANDLER, 'eventName', 'eventHandlerFunctionOne');
$xajax->register(XAJAX_EVENT_HANDLER, 'eventName', 'eventHandlerFunctionTwo');
$xajax->register(XAJAX_EVENT_HANDLER, 'eventName', 'eventHandlerFunctionThree');

[edit] xajaxRequest class

A new class has been added to handle the generation of javascript code to call xajax registered functions, objects and events. This further removes the need to hand code javascript in your xajax enabled pages. As seen in the example code above the xajax register function returns a xajaxRequest object. This object can be configured with parameter values and then used to generate a javascript function call that can be applied to a javascript event.

$requestTriggerEvent_EventName = $xajax->register(XAJAX_EVENT, 'eventName');
<INPUT type='checkbox' onclick='<?php $requestTriggerEvent_EventName->printScript(); ?>' />

produces:

<INPUT type='checkbox' onclick='if (false == xajax_event_eventName()) return false;' />

xajax will generate a function stub in the head of the page, then the xajaxRequest object will generate the javascript function call and parameters for the onclick.

$requestTriggerEvent_EventName = $xajax->register(XAJAX_EVENT, 'eventName');
$requestTriggerEvent_EventName->setParameter(0, XAJAX_INPUT_VALUE, 'cbxOne');
<INPUT type='checkbox' id='cbxOne' 
    onclick='<?php $requestTriggerEvent_EventName->printScript(); ?>' />

produces:

<INPUT type='checkbox' id='cbxOne' 
    onclick='if (false == xajax_event_eventName(xajax.$("cbxOne").value)) return false;' />

NOTE: It is important to use the xajaxRequest object to generate the javascript where possible; this will be more reliable as xajax is developed. As new techniques are discovered and new features are added, the xajaxRequest object will be improved. Thus, the javascript produced by this class will be improved as well. If you hand code the javascript calls, those scripts will have to be modified by hand as you upgrade xajax. (that can be cumbersome and error prone)

[edit] xajax HTML control library

A new collection of classes has been added so that it is now possible to construct your pages and HTML updates in an object oriented manner. The xajaxControl and xajaxControlContainer classes provide the base functionality for the control library. A base set of controls is included in the beta 3 release, including the document, head, body, div, input, textarea, select/option, table/tablerow/tablecell/tableheader/tablebody/tablefooter and label controls.

Controls can be configured by passing a configuration array to the constructor, or by calling setAttribute, setEvent and (for containers) addChild. Once the heirarchy of controls is constructed, your script can call the printHTML function to send the entire heirarcy of controls to the browser. In addition, a getHTML function is provided so that the HTML can be sent back as part of a xajax response.

It is important to note that xajaxRequest objects can be used in the configuration of control events. The javascript produced by the xajaxRequest object is included in the HTML of the output from the control library. This further automates the generation of the output that is sent to the browser. The control library will help to validate your HTML and javascript output, thus reducing errors.

[edit] Made call options reusable

Further cleanup of call process now allows call options to be retained and reused:

  • parameters are left intact
  • request object is undefined upon completion
  • request data is undefined upon completion
  • request URI is reset (rebuilt at time of call)

This means that you can create a set of call options:

myCallOptions = { parameters: [ xajax.getFormValues('myForm'), 100 ], method: 'GET', mode: 'synchronous' };

and then use them over and over:

xajax.call('myFunction', myCallOptions);
xajax.call('myOtherFunction', myCallOptions);


[edit] Allowed setting of timeout for waitFor response command

When using the waitFor response command, you must now specify the timeout value (in tenths of a second):

$objResponse->waitFor('100 == myVariable', 500); // will automatically proceed after 5 seconds


[edit] Added setFunction, wrapFunction response commands

You can now (more easily) create javascript functions from your php scripts using:

$objResponse->setFunction('myJsFunction', 'arg1, arg2', 'if (100 == arg1) alert(arg2);');

and then you can wrap some additional code around javascript functions using:

$objResponse->wrapFunction('myJsFunction', 
    'arg1, arg2', 
    array('if (50 == arg1) alert("invalid value: 50");', 'if (200 == arg1) returnValue = confirm(arg2);'), 
    'returnValue'
    );

The end result will look like this:

myJsFunction = function(arg1, arg2) {
    if (50 == arg1) alert("invalid value: 50");
    returnValue = originalFunction(arg1, arg2);
    if (200 == arg1) returnValue = confirm(arg2);
    return returnValue;
}

More advanced constructs are possible, but beyond the scope of this document.


[edit] Added sleep response command

You can now instruct xajax to pause while processing your response commands using:

$objResponse->sleep(100); // will sleep for 1 second (value in tenths of a second)

[edit] Bug fixes

In _nodeToObject, changed 'new Array' to 'new Object' to avoid problems with using 'length' as a parameter key.
See forum post: http://community.xajaxproject.org/viewtopic.php?id=3910


  • Author: CtC - Joseph Woolley - 2007/03/20

[edit] Encoding bug

[edit] "Symptoms"

I can't get any response, using in this response cyrillic letters ('windows-1251' encoding). If I use latin letters only, response returns.

[edit] Reason

Class xajaxResponse in xajaxResponse.inc.php has some mistakes that make unavailable using of any other encoding but 'UTF-8'. Variable $sEncoding is called now $sCharacterEncoding (since v. 0.5 as I can understand looking throw comments), but it is still used as $this->sEncoding in _printHeader, _printXML and _escape functions. For it is so, response contains XML-header <?xml version="1.0" encoding=""?> that browser recognizes as 'UTF-8'.

[edit] Fix

Replace $this->sEncoding by $this->sCharacterEncoding (total 7 times in 3 functions).

UBaHoB 16:30, 26 August 2007 (EDT)