Ajax form taglib ver. 1.2


    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.
2) name Optional parameter. Describes a name for your form.
3) method Optional parameter. Describes a method for your form. Possible values are get or post. Default value is get.
4) action Optional parameter. Describes an URL for your form. By default it will be the same JSP file.
5) handler Optional parameter. Describes a function for the customized processing.
6) error Optional parameter. Describes a name for your own JavaScript function that will be called in case of errors. By default is empty.
7) beforeAction Optional parameter. Describes a JavaScript function that will be called before the request.
8) afterAction Optional parameter. Describes a JavaScript function that will be called upon the request completion.
9) onSubmit Optional parameter. Describes a JavaScript function for the validation before submitting.
 

for downloading:

 Library: ajaxformtag.jar     Description: taglib.tld  JavaScript library: cjajax.js  Progress indicator: Prograss indicator

 © Coldbeans      Comments?

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

     

Also in Coldtags: