Custom JSP taglib with Ajax support. Lets you create HTML select where any selection allows you to retrieve a list of values from a backend servlet (or other server-side control like JSP) and display them in another HTML select box. In other words you can create a master control and fill a slave (dependent) control based on the master's selection. In order to use this tag you have to describe an external JavaScript file cjajax.js on your page. For example:
<script language="JavaScript" src="cjajax.js"></script> <%@ taglib uri="taglib.tld" prefix="as" %> Master list <as:ajaxselect slaveId="id1" url="/action.do" size="1"> <as:option value="1">Java</as:option> <as:option value="2">C#</as:option> </as:ajaxselect> ... Slave list <select id="id1"> </select> And now user's selection in the master list will perform the following request: /action.do?master=1 or /action.do?master=2. Here /action.do is an URL provided as an atrribute, master is a default parameter name for the selected value. Tag assumes that your server side returns XML with data for the slave control. E.g.:
<?xml version="1.0" encoding="ISO-8859-1" ?> <ajaxselect> <option value="1">Jdeveloper</option> <option value="2">JBuilder</option> etc. </ajaxselect> Tag will parse the response and fill your slave select control identified by the attribute slaveId. Note: if you are generating XML in JSP file make sure there are no empty lines or whitespace before the <?xml ... ?> line. You may obtain master's options through some array (collection, iterator etc.) and use this object for
building your control:
<% java.util.Vector v=new java.util.Vector(); v.addElement("Java"); ... %> <as:ajaxselect source="<%=v%>" url="/servlet/MVC" slaveId="id1"/> In this example (our collection contains Strings) tag iterates over elements and creates the control. You can pass a collection of beans also and describe how to get the value and text for options. Attribute option specifies what getXXX method is called on each item in your source for getting options. Attribute value does the same for values. E.g. option="name" means that that getName() call is used for getting options etc. As a slave select box you can use a standard HTML select, select taglib from Coldtags suite or even another ajax select. Tags are: ajaxselect Body tag. Creates select control that fills another select box. Parameters are: 1) name name for element
option Body tag. Describes an option for select control (as tag's body). Parameters are: 1) value Optional parameter. Describes a value for this option.
selectedIndex Body tag lets you set an index for selected element. Tag's body presents an index (starting from 1) for option. Option's state will be set to selected. Parameters are: none selectedValue Body tag lets you set a value for selected element. Tag's body presents a value for option. Option's state will be set to selected. Parameters are: none for downloading: Library: ajaxseltag.jar Description: taglib.tld JavaScript library: cjajax.js See also Coldtags suite - the largest collection of custom JSP tags. |
Also in Coldtags:
|