This site will look much better in a browser that supports web standards, but it is accessible to any browser or Internet device.
The "isq" (Aka I Ask You) tag extension library helps you to made HTML form simple.
Inspired by the "input" tag of The Apache Software Foundation (http://www.apache.org/), isq adds a support for client-side input validation by JavaScript checking.
Like the original library isq can prepopulate form element getting values back from a request or a JavaBean.
Enabling javascript check, you can easily choose which input are mandatory and which not before the form will be submitted.
Enjoy with "input", "checkbox", "select", "radio" and "textarea".
NOTICE:
This product includes software developed by The Apache Software Foundation (http://www.apache.org/).
You can find useful using ISQ to build your registration or login form without spending a lot of time writing logical code to prepopulate fields or adding javascript checking
Without isq:
..... ...... <scipt language="JavaScript"> function myFormValidator(f){ if (f.username.value == ""){ alert('Please fill username'); return false; } .... .... rerurn true; } </script> <form name="LoginForm" method="POST" onSubmit="return myFormValidator(this);" > Username: <input type="text" name="user" value="<%=request.getParameter("user")%>" /></br> Password: <input type="password" name="pass" value="<%=request.getParameter("pass")%>"/> <input type="submit"/> </form>
With ISQ:
<%--> The taglib directive below imports the ISQ Library. --%> <%@taglib uri="http://www.cianciolab.com/taglibs/taglib-isq" prefix="isq"%> ..... ..... ..... <isq:form name="ISQ_Form" method="post" jsValidation="true" action="some.jsp"> Username: <isq:text name="user" required="true" jsAlert="Please fill username"/> Password: <isq:text name="password" required="true" jsAlert="Please fill password"/> <input type="submit"/> </isq:form>
That's it!
Like the "input" taglib provided by The Apache Software Foundation, ISQ looks for value by:
At first ISQ looks for a bean named as bean attribute of the tag or for main form's bean attribute. If exists a getter with the same name of the tag's name attribute then that property is the value of the tag.
Then if request (POST or GET) contains a value named as one of the tags present into the ISQ "form", so that value is the value of the tag
At least, if a value has not found and the default attribute is filled, then that value is the value of the tag
To enable this feature just add jsValidation=true into isq:form tag
For each fields with attribute required=true, a simple javascript cheking mathod against empty
values will be added after jsp compilation
The output source of the scenario above looks like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>ISQ Example</title> </head> <body> <script language="JavaScript"> function ISQ_FormValidator_ISQ_DemoForm(f){ //Text checking// var INPUT_username= f.username; var W_INPUT_username= 'Please fill Username field'; if (INPUT_username.value == ""){ alert(W_INPUT_username); if (INPUT_username.focus){ INPUT_username.focus(); } return false; } //Text checking// var INPUT_password= f.password; var W_INPUT_password= 'Please fill Password field'; if (INPUT_password.value == ""){ alert(W_INPUT_password); if (INPUT_password.focus){ INPUT_password.focus(); } return false; } } </script> <form name="ISQ_DemoForm" onSubmit="return ISQ_FormValidator_ISQ_DemoForm(this);" > Username:<input type="text" name="username" value="" /><br/> Username:<input type="text" name="password" value="" /><br/> <input type="submit" value="Submit Form"/> </form> </body> </html>
ISQ provide you a simple tag isq:jschek for appending custom JavaScript code at the generated control function:
<isq:form name="ISQ_Form" method="post" jsValidation="true" action="some.jsp"> Username: <isq:text name="user" required="true" jsAlert="Please fill username"/> Password: <isq:text name="password" required="true" jsAlert="Please fill password"/> <input type="submit"/> <isq:jscheck> //Custom javascript if (!confirm("Are you shure?")) return false; </isq:jschek> </isq:form>
<taglib> <taglib-uri>http://www.cianciolab.com/taglibs/taglib-isq</taglib-uri> <taglib-location>/WEB-INF/taglib-isq.tld</taglib-location> </taglib>For more informations about these steps please consult the documentations of your ServletContainer
JSP Tag | Summary |
---|---|
form | Creates a form tag |
text | Displays a text box |
password | Displays password box |
hidden | Creates a hidden field |
textarea | Displays a textarea |
select | Displays a select |
option | Displays a select option (used in conjuction with select) |
radiogroup | Initialize a radiobutton group |
radio | Displays a radio button (used in conjuction with radio) |
checkbox | Displays a checkbox |
jscheck | Add custom js code |
For sensible data i suggest you to add a server side validation too
ISQ is still beta! That means is not enough tested, documentation could be inaccurate and tag's usage or API call could be changed