Ajax timer taglib ver. 1.3

    Custom JSP taglib lets you periodically perform Ajax requests. Taglib defines a timer that asynchronously requests your server side (JSP, servlet). For example:
 


<script language="JavaScript" src="cjajax.js"></script>

<%@ taglib uri="taglib.tld" prefix="a" %>

<a:AjaxTimer id="i1" url="newContent.jsp" timeout="10" handler="myHandler">

In this example your file newContent.jsp will be requested each 10 seconds.

An optional parameter handler lets you provide your own JavaScript function that will accept the requested data. This function will get two parameters: obtained text and obtained XML document:
 


<script language="JavaScript">
function myHandler(txt, xmlDoc)
{
  your own processing for the requested content
}
</script>

an optional parameter error lets you provide your own error handler for failed requests:


<script language="JavaScript" src="cjajax.js"></script>

<script language="JavaScript">
function onError() { alert("Count not get data"); }
</script>

Attributes beforeAction and afterAction lets you provide your own JavaScript code that marks start/end phase of request. For example you can show/hide here some loading image etc. So, you can describe in your HTML code some progress indicator:
 


<div style="display:none" id="loading"><img src="loading.gif"/></div>

and define two JavaScript functions:
 


function beforeAction()
{
document.getElementById("loading").style.display="block";
}

function afterAction()
{
document.getElementById("loading").style.display="none";
}

it lets you show/hide progress indicator

Timeout will be available through the JavaScript variable described in the attribute id. E.g. in the above mentioned example (timer id is i1) you can stop process by this call: clearTimeout(i1).

In order to use this tag you have to describe an external JavaScript file cjajax.js on your page.

Url used for the server side request could be calculated in some JavaScript function. It is described in the attribute urlFunction. See JavaScript link taglib also. E.g. the typical use case when your own function collects data from some form and returns the target url with parameters.

A negative value for timeout attribute simply disables the requests.

Tags are:

AjaxTimer

Tag defines Ajax based timer. Parameters are:

1) url Optional parameter. Describes an URL for your requests.
2) urlFunction Optional parameter. Describes a function that will return an url.
3) handler Optional parameter. Describes a name for your own JavaScript function that will accept the requested content. By default this function is empty.
4) error Optional parameter. Describes a name for your own JavaScript function that will be called in case of errors. By default is empty.
5) timeout Optional parameter. Describes a timeout for the periodical calls (in seconds). Default value is 10.
6) id Optional parameter. Describes an id for your timer.
7) beforeAction Optional parameter. Describes a name for your own JavaScript function that will be called at the beginning of request. By default is empty.
8) afterAction Optional parameter. Describes a name for your own JavaScript function that will be called at the end of request. By default is empty.
 

for downloading:

 Library: ajaxtimertag.jar     Description: taglib.tld  JavaScript library: cjajax.js

 © Coldbeans      Comments?

See also Coldtags suite - the largest collection of custom JSP tags.

Also in Coldtags: