Custom JSP taglib lets you periodically perform Ajax requests. Taglib defines a timer
that asynchronously requests your server side (JSP, servlet). For example:
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:
an optional parameter error lets you provide your own error handler for failed requests:
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:
and define two JavaScript functions:
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.
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
See also Coldtags suite - the largest collection of custom JSP tags.
Related links: