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.
for downloading: Library: ajaxtimertag.jar Description: taglib.tld JavaScript library: cjajax.js See also Coldtags suite - the largest collection of custom JSP tags.
|
Also in Coldtags:
|