Custom JSP taglib lets you mimic HTML form with Ajax request. Tag AjaxForm performs
HTTP GET/POST request provided in form's action attribute via Ajax. For example:
<%@ taglib uri="taglib.tld" prefix="a" %> <a:AjaxForm method="post" action="/servlet/MVC"> <input type="text" name="username"> <input type="submit"> </a:AjaxForm> Here tag lets you asynchronously submit request to /servlet/MVC. In order to use this tag you have to describe an external JavaScript file cjajax.js on your page. 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 attribute error lets you provide you own JavaScript function that will reports about errors. For example here we are updating some div area via Ajax call: <script language="JavaScript"> function myHandler(txt, xmlDoc) { document.getElementById("mydiv").innerHTML=txt; } function error() { alert("Could not execute your request"); } </script> <a:AjaxForm method="post" action="/servlet/MVC" handler="myHandler" error="error"> ... </a:AjaxForm> Also you can provide your own JavaScript functions that will be executed before and after the request. For example here we are showing/hiding progress indicator: <script language="JavaScript"> function beforeAction() { document.getElementById("progress").style.display='block'; } function afterAction() { document.getElementById("progress").style.display='none'; } </script> <img id="progress" style="position:absolute; left:5px; top:5px; border:none; display:none" src="rotation.gif" alt="Wait, please"/> <a:AjaxForm method="post" action="/servlet/MVC" handler="myHandler" error="error" beforeAction="beforeAction" afterAction="afterAction"> ... </a:AjaxForm> Tags are: AjaxForm Body tag mimics HTML form for Ajax. Parameters are: 1) id Optional parameter. Describes a CSS/DHTML id for your form.
for downloading: Library: ajaxformtag.jar Description: taglib.tld JavaScript library: cjajax.js Progress indicator: See also Coldtags suite - the largest collection of custom JSP tags. |
Also in Coldtags:
|