Chapter 9. Javascript Libraries

9.1. Third-party Javascript Libraries

Aranea distribution includes some third party Javascript libraries. Most of these are not needed for using Aranea functionality, but extend the functionality of both framework and UiLib.

9.1.1. Behaviour (http://bennolan.com/behaviour/)

Neat little library allowing usage of CSS selectors for applying behaviour to HTML page elements. It is required for full function of Aranea pages rendered with Aranea JSP tags. With standard Behaviour rules, following functionality is provided:

  • keyboard handlers are registered for form elements.
  • addition of urls (<href="...") to page elements that allow cloning of the session thread (opening link in new window—and in different session thread).

AjaxAnywhere allows separating web page into multiple zones, and refreshing only those zones that needs to be updated. Inclusion of this library is required for building AJAX capable web-page with Aranea JSP tags.

9.1.3. The DHTML Calendar (http://www.dynarch.com/projects/calendar/)

Nice DHTML calendar, required if one wants to use Aranea JSP <ui:dateInput> or <ui:dateTimeInput> tags.

9.1.4. Prototype (http://www.prototypejs.org/)

Prototype is a JavaScript framework that aims to ease development of dynamic web applications. Aranea JSP aims to make more use of it in the future. It is a prerequisite for using Uilib's AutoCompleteTextControl and action-enabled TreeWidget components.

9.1.5. script.aculo.us (http://script.aculo.us/)

script.aculo.us provides easy-to-use, cross-browser user interface JavaScript libraries. Only subset of script.aculo.us libraries are included—only JSP tag that depends on it is <ui:autoCompleteTextInput>.

TinyMCE is a platform independent web based Javascript HTML WYSIWYG editor control. Required for using Aranea JSP <ui:richTextarea> tag.

log4javascript is a JavaScript logging framework similar to Java logging framework log4j. Include log4javascript scripts and call AraneaPage.setDefaultLogger() to receive a popup window where Aranea JS debug output is logged.

9.2. Aranea Clientside Javascript

Aranea uses javascript to do form submits. This provides AJAX enabled webapps and more control over form submitting logic. Each page served with Aranea has associated AraneaPage object:

/* AraneaPage object is present on each page served by Aranea and contains common
 * functionality for setting/getting page related variables, events and functions. */
function AraneaPage() {
  /* Getters and setters for URL of aranea dispatcher servlet serving current page. */ 
  function getServletURL();
  function setServletURL(url);
  
  /** Indicates whether the page is completely loaded or not. Page is considered to 
   * be loaded when all system onload events have completed execution. */
  function isLoaded();
  function setLoaded(loaded);
  
  /* Returns the server-side reported locale (AraneaLocale). */
  function getLocale();

  /** Indicates whether some form on page is (being) submitted already
    * by traditional HTTP request. */
  function isSubmitted();
  /* Custom submit functions using plain HTTP request should call this before submit. */
  function setSubmitted();
  
  /** Returns Aranea JSP specific DOM tree traverser (AraneaTraverser). */
  function getTraverser();

  /** Add events that should be executed upon page load/unload to execution queue. */
  function addSystemLoadEvent(event);
  function addClientLoadEvent(event);
  function addSystemUnLoadEvent(event);

  /** Called on page load, executes registered system -- after which page is considered 
    * loaded and client load events are executed too. */
  function onload();
  /** Called on page load, executes registered unload events. */
  function onunload();
  
  /** Adds general callback executed before any form submit. */
  function addSubmitCallback(callback);

  /** Adds general callback executed before form with given id is submitted. */
  function addSubmitCallback(systemFormId, callback);

  /** Executes all callbacks that should run before submitting the form with given id. */
  function executeCallbacks(systemFormId);

  /** 
   * Chooses appropriate submitting method and submittable form given the HTML element
   * that initiated the submit request. */
  function event(element);

  /** 
   * Called by event() to determine the appropriate form submitter.
   */
  function findSubmitter(element, systemForm);

  /** another submit function, takes all params that are possible to 
    * use with Aranea JSP currently. */
  function event_6(systemForm, eventId, eventTarget, 
                    eventParam, eventPrecondition, eventUpdateRegions);
                    
  /** 
   * Provides preferred way of overriding AraneaPage object functions. 
   * @param functionName name of AraneaPage function that should be overridden. 
   * @param f replacement function 
   */
  function override(functionName, f);
  
  /** 
   * Adds keepalive function f that is executed periodically after time 
   * milliseconds has passed 
   */
  function addKeepAlive(f, time);

  /** Clears/removes all registered keepalive functions. */
  function clearKeepAlives();
  
  /** Logs message on DEBUG level, if logger is present. */
  function debug(message);
}

/** Random request id generator. Sent only with AA ajax requests.
  * Currently only purpose of it is easier debugging (identifying requests). */
function AraneaPage.getRandomRequestId();

/* Returns a default keepalive function -- to make periodical requests to expiring thread
 * or top level services. */
AraneaPage.getDefaultKeepAlive = function(topServiceId, threadServiceId, keepAliveKey);

/** Page initialization function, should be called upon page load. */
AraneaPage.init();

/* Aranea page object is accessible in two ways -- _ap and araneaPage() */
_ap = new AraneaPage();
function araneaPage() { return _ap; }