Usage

Base URL

The baseUrl property is used by the tag to make a request to the server side. The responding resource (e.g., servlet, JSP, etc.) is responsible for returning the response in the appropriate format (plain text, HTML, XML, etc.). This take is used as a normal URL you are able to append parameters.

Parameters

Each tag has a common parameters property, composed of name-value pairs that eventually get passed to the URL specified in the baseUrl property. You may specify multiple name-value pairs by separating them with commas. Within each pair, you can also indicate that you want a certain form field value to be inserted at the time the request is made by surrounding the value with curly brackets.

Let's look at an example. Assume we want to pass two parameters on the URL, one indicating the make of our automobile and another that is a plain text constant. The value of the make parameter will be inserted at request time. In this case, we assume the makeId form field contains a value of "Honda".

parameters="make={makeId},q=someConstantValue"

...will be replaced at request time with...

parameters="make=Honda,q=someConstantValue"
Implicit Parameters

The ajax:htmlContent and ajax:callout tags will accept an implicit parameter in place of the value of the source element. For instance, if you want to include the value of the source element on the querystring when making the AJAX call, simply define the parameters attribute as follows:

parameters="someId={ajaxParameter}"

Pre- / Post- and Error Functions

If you will invoke a JavaScript function before the request is started for example to modify the parameters you can use the preFunction.

If you've wondered how to either chain AJAX tags together by having one execute after another has completed then you'll like this. The postFunction attribute allows you do just that. This attribute expects a JavaScript function name to be passed. The AJAX JavaScript will execute the function you define after it has finished its work.

In addition to post-functions, you may also define functions to be executed when the AJAX request could not be completed (e.g., invalid URL, server exception). You simply enter the name of the user-defined JavaScript function into the optional errorFunction tag attribute.

ajax:anchors

The anchors tag will convert any HTML anchor tags (<A>) within it's area to be AJAX-enabled. Essentially the href is removed and its contents placed within an onclick event for the anchor, thus forcing the resource to be accessed through AJAX instead. The response will then be loaded in any area on the page you define.

<ajax:anchors target="ajaxFrame">
  <!-- Ajax this link -->
  Refresh first area <a href="pagearea.jsp" class="contentLink"></a>
</ajax:anchors>

<div id="ajaxFrame"></div>
ParameterDescriptionRequired
targetThe target region on the page where the AJAX response will be written, often a DIV tagyes

ajax:area

The area tag lets you wrap a piece of the webpage and force all links and resources to be loaded inside of it instead of refreshing the entire page.

If you use ajaxAnchors your content have to be xhtml conform.

<ajax:area id="ajaxFrame"
  styleClass="textArea"
  ajaxAnchors="true">
  This is the first area and should be refreshed only when the first link or
  the link inside itself is clicked:

  It may include a link to <a href="${contextPath}/pagearea.jsp"> itself </a>
</ajax:area>
ParameterDescriptionRequired
idName of ID used for enclosing DIV tag written by tagyes
styleClassCSS class name to useno
ajaxAnchorsWhether to rewrite HTML anchor tags with an onclick eventno

ajax:autocomplete

The autocomplete tag allows one to retrieve a list of probable values from a backend servlet (or other server-side control) and display them in a dropdown beneath an HTML text input field. The user may then use the cursor and ENTER keys or the mouse to make a selection from that list of labels, which is then populated into the text field. This JSP tag also allows for a second field to be populated with the value or ID of the item in the dropdown.

<form>
  Make: <input id="model" name="model" type="text" size="30" class="form-autocomplete" />
  Model: <input id="make" name="make" type="text" size="30" />
</form>

<ajax:autocomplete
  baseUrl="${pageContext.request.contextPath}/GetModel.view"
  source="make"
  target="model"
  parameters="model={model}"
  className="autocomplete"
  indicator="throbbing"
  minimumCharacters="1" />

Note: Tag must appear AFTER the web form.

ParameterDescriptionRequired
varName of the JavaScript object createdno
attachToName of the JavaScript object to which autocompleter will attach. You must define 'var' for this to work.no
baseUrlURL of server-side action or servlet that processes search and returns list of values used in autocomplete dropdown; expression language (EL) is supported for this fieldyes
sourceText field where label of autocomplete selection will be populated; also the field in which the user types out the search stringyes
targetText field where value of autocomplete selection will be populated; you may set this to the same value as the source fieldyes
parametersA comma-separated list of parameters to pass to the server-side action or servletyes
classNameCSS class name to apply to the popup autocomplete dropdownyes
indicatorID of indicator region that will show during Ajax request callno
minimumCharactersMinimum number of characters needed before autocomplete is executedno
appendSeparatorThe separator to use for the target field when values are appended [default=space]. If appendValue is not set or is set to "false", this parameter has no effect.no
preFunctionFunction to execute before Ajax is begunno
postFunctionFunction to execute after Ajax is finished, allowing for a chain of additional functions to executeno
errorFunctionFunction to execute if there is a server exception (non-200 HTTP response)no
parserThe response parser to implement [default=ResponseHtmlParser]no

ajax:callout

The callout tag is an easy way to attach a callout or popup balloon to any HTML element supporting an onclick event. The style of this callout is fairly flexible, but generally has a header/title, a close link ('X'), and the content itself, of course. All of this (since AjaxTags 1.2) is handled by the OverLIBMWS JavaScript library. See http://www.macridesweb.com/oltest/ for complete instructions on using OverLIBMWS.

<div>
  <p>
    The Hitchhiker's Guide to the Galaxy is a science fiction series written by Douglas Adams
    (1952 - 2001).  The series follows the adventures of
    <a href="#" class="definition">Arthur Dent</a>, a hapless
    <a href="#" class="definition">Englishman</a> who escapes the destruction of Earth by an alien
    race called the <a href="javascript://nop/" class="definition">Vogons</a> with his friend
    <a href="#" class="definition">Ford Prefect</a>, an alien from a small planet somewhere in the
    vicinity of <a href="#" class="definition">Betelgeuse</a> and researcher for the eponymous
    guide.
  </p>
</div>

<ajax:callout
  baseUrl="${pageContext.request.contextPath}/GetInfo.view"
  sourceClass="definition"
  parameters="q={ajaxCallout}"
  title="Definition"
  overlib="STICKY,CLOSECLICK,DELAY,250,TIMEOUT,5000,VAUTO,WRAPMAX,240" />

Note: Tag must appear AFTER the web form.

ParameterDescriptionRequired
varName of the JavaScript object createdno
attachToName of the JavaScript object to which callout will attach. You must define 'var' for this to work.no
baseUrlURL of server-side action or servlet that processes a simple commandyes
sourceID of the element to which the callout will be attachedeither source or sourceClass must be defined
sourceClassCSS class name of the elements to which the callout will be attachedeither source or sourceClass must be defined
parametersA comma-separated list of parameters to pass to the server-side action or servletyes
titleTitle for callout's box header. If useTitleBar==false and no title is specified, then the value attribute of the returned XML will be used as the title.no
overlibOptions for OverLibno
preFunctionFunction to execute before Ajax is begunno
postFunctionFunction to execute after Ajax is finished, allowing for a chain of additional functions to executeno
errorFunctionFunction to execute if there is a server exception (non-200 HTTP response)no

ajax:displayTag

The displayTag is similar to the area tag, but it specifically tailored to the Display Tag. It wraps DisplayTag ajaxing pagination and sorting.

If you use this tag your content have to be xhtml conform.

<ajax:displayTag id="displayTagFrame">

  <display:table name="service.allCars" class="displaytag" pagesize="10" scope="page"
    defaultsort="1" defaultorder="descending" export="true" id="row" excludedParams="ajax">
    <display:column property="make" title="Make" sortable="true" headerClass="sortable" />
    <display:column property="model" title="Model" sortable="true" headerClass="sortable" />
    <display:column title="Link" media="html">
      <a href="http://www.${row.make}.com">${row.make} Web Page</a>
    </display:column>
    <display:column title="Link" media="excel xml">
      www.${row.make}.com
    </display:column>
  </display:table>

</ajax:displayTag>
ParameterDescriptionRequired
idName of ID used for enclosing DIV tag written by tagyes
pagelinksClassCSS class name of the DisplayTag's navigation links [default="pagelinks"]no
columnClassThe CSS class of the TD within the THEAD of the table that should have their HREFs rewritten [default="sortable"]no
postFunctionFunction to execute after Ajax is finished, allowing for a chain of additional functions to executeno
parametersA comma-separated list of parameters to pass to the server-side action or servletfalse

ajax:htmlContent

The HTML content tag allows you to fill a region on the page (often a DIV tag) with any HTML content pulled from another webpage. The AJAX action may be activated by attaching it to an anchor link or form field.

This tag expects an HTML response instead of XML and the AJAX function will not parse it as XML; it will simply insert the content of the response as is.

<div id="modelDescription"></div>
<div id="htmlContentForm">
  <p>Select by ANCHOR link.</p>
  <ul>
    <li><a href="javascript://nop/" class="contentLink">Ford</a></li>
    <li><a href="javascript://nop/" class="contentLink">Honda</a></li>
    <li><a href="javascript://nop/" class="contentLink">Mazda</a></li>
  </ul>
</div>

<ajax:htmlContent
  baseUrl="${pageContext.request.contextPath}/htmlcontent.view"
  sourceClass="contentLink"
  target="modelDescription"
  parameters="q={ajaxParameter}" />

Note: Tag must appear AFTER the web form.

ParameterDescriptionRequired
varName of the JavaScript object createdno
attachToName of the JavaScript object to which htmlContent will attach. You must define 'var' for this to work.no
baseUrlURL of server-side action or servlet that processes a simple commandyes
sourceID of the element to which the event will be attachedeither source or sourceClass must be defined
sourceClassThe CSS class name of the elements to which the event will be attachedeither source or sourceClass must be defined
targetID of DIV tag or other element that will be filled with the response's HTMLyes
parametersA comma-separated list of parameters to pass to the server-side action or servletyes
eventTypeSpecifies the event type to attach to the source field(s)no
preFunctionFunction to execute before Ajax is begunno
postFunctionFunction to execute after Ajax is finished, allowing for a chain of additional functions to executeno
errorFunctionFunction to execute if there is a server exception (non-200 HTTP response)no

ajax:portlet

The portlet tag simulates a a href="http://www.jcp.org/en/jsr/detail?id=168"JSR-168/a style portlet by allowing you to define a portion of the page that pulls content from another location using Ajax with or without a periodic refresh.

This tag expects an HTML response instead of XML and the AJAX function will not parse it as XML; it will simply insert the content of the response as is.

<ajax:portlet
  source="portlet_1"
  baseUrl="${pageContext.request.contextPath}/htmlcontent.view?make=ford"
  classNamePrefix="portlet"
  title="Ford Portlet"
  imageClose="${pageContext.request.contextPath}/img/close.png"
  imageMaximize="${pageContext.request.contextPath}/img/maximize.png"
  imageMinimize="${pageContext.request.contextPath}/img/minimize.png"
  imageRefresh="${pageContext.request.contextPath}/img/refresh.png" />
ParameterDescriptionRequired
varName of the JavaScript object createdno
attachToName of the JavaScript object to which portlet will attach. You must define 'var' for this to work.no
baseUrlURL of server-side action or servlet that processes a simple commandyes
sourceID of the portletyes
parametersA comma-separated list of parameters to pass to the server-side action or servletno
classNamePrefixCSS class name prefix to use for the portlet's 'Box', 'Tools', 'Refresh', 'Size', 'Close', 'Title', and 'Content' elementsyes
titleTitle for portlet headeryes
imageCloseImage used for the close iconno
imageMaximizeImage used for the maximize iconno
imageMinimizeImage used for the minimize iconno
imageRefreshImage used for the refresh iconno
refreshPeriodThe time (in seconds) the portlet waits before automatically refreshing its content. If no period is specified, the portlet will not refresh itself automatically, but must be commanded to do so by clicking the refresh image/link (if one is defined). Lastly, the refresh will not occur until after the first time the content is loaded, so if executeOnLoad is set to false, the refresh will not begin until you manually refresh the first time.no
executeOnLoadIndicates whether the portlet's content should be retrieved when the page loads [default=true]no
preFunctionFunction to execute before Ajax is begunno
postFunctionFunction to execute after Ajax is finished, allowing for a chain of additional functions to executeno
errorFunctionFunction to execute if there is a server exception (non-200 HTTP response)no

ajax:select

The select tag allows one to retrieve a list of values from a backend servlet (or other server-side control) and display them in another HTML select box.

<form>
  Make:
  <select id="make" name="make">
    <option value="">Select make</option>
    <c:forEach items="${makes}" var="make">
      <option value="${make}">${make}</option>
    </c:forEach>
  </select>

  Model:
  <select id="model" name="model">
    <option value="">Select model</option>
  </select>
</form>

<ajax:select
  baseUrl="${pageContext.request.contextPath}/GetCarModel.view"
  source="make"
  target="model"
  parameters="make={make}"
  postFunction="doOtherThings" />

Note: Tag must appear AFTER the web form.

ParameterDescriptionRequired
varName of the JavaScript object createdno
attachToName of the JavaScript object to which select will attach. You must define 'var' for this to work.no
baseUrlURL of server-side action or servlet that processes a simple commandyes
sourceThe initial select field that will form the basis for the search via AJAXyes
targetSelect field where value of AJAX search will be populatedyes
parametersA comma-separated list of parameters to pass to the server-side action or servletno
eventTypeSpecifies the event type to attach to the source field(s)no
executeOnLoadIndicates whether the target select/dropdown should be populated when the object is initialized (this is essentially when the form loads) [default=false]no
defaultOptionsA comma-seperated list of values of options to be marked as selected by default if they exist in the new set of optionsno
preFunctionFunction to execute before Ajax is begunno
postFunctionFunction to execute after Ajax is finished, allowing for a chain of additional functions to executeno
errorFunctionFunction to execute if there is a server exception (non-200 HTTP response)no
parserThe response parser to implement [default=ResponseHtmlParser]no

ajax:tabPanel

Provides a tabbed page view of content from different resources

<ajax:tabPanel
    id="ajaxCurrentTab">
  <ajax:tab caption="Ford"
    baseUrl="${pageContext.request.contextPath}/htmlcontent.view?make=ford"
    defaultTab="true"/>
  <ajax:tab caption="Honda"
    baseUrl="${pageContext.request.contextPath}/htmlcontent.view"
    parameters="make=honda"/>
  <ajax:tab caption="Mazda"
    baseUrl="${pageContext.request.contextPath}/htmlcontent.view"
    parameters="make=mazda"/>
</ajax:tabPanel>

ajax:tabPanel

ParameterDescriptionRequired
idID of the tab panelyes
preFunctionFunction to execute before Ajax is begunno
postFunctionFunction to execute after Ajax is finished, allowing for a chain of additional functions to executeno
errorFunctionFunction to execute if there is a server exception (non-200 HTTP response)no
parserThe response parser to implement [default=ResponseHtmlParser]no

ajax:tab

ParameterDescriptionRequired
baseUrlThe URL to use for the AJAX action, which will return content for this tabyes
captionThe caption for this tabyes
defaultTabIndicates whether this tab is the initial one loaded [truefalse]
parametersA comma-separated list of parameters to pass to the server-side action or servletno

ajax:toggle

The toggle tag uses a single image to represent the display of the ratings with the help of CSS to manage the mouseover/mouseout. Additionally, you may supply the tag with a form field to hold the value of the selected rating.

<!-- To hold value of the selected rating; maps to the 'state' attribute -->
<form id="toggleForm" action=".">
  <input type="hidden" id="raterField" />
</form>

<h4>AJAX Rating System <span style="font:normal 8pt Verdana;">[${toggleRating}]</span></h4>
<ajax:toggle
  baseUrl="${pageContext.request.contextPath}/toggle.view"
  source="rater1"
  ratings="One,Two,Three,Four,Five"
  defaultRating="${toggleRating}"
  containerClass="star-rating"
  messageClass="star-rating-message"
  selectedClass="selected"
  selectedOverClass="selectedover"
  selectedLessClass="selectedless"
  overClass="over"
  onOff="false"
  state="raterField"
  preFunction="initProgress"
  postFunction="resetProgress"
  errorFunction="reportError"
  />

Note: Tag must appear AFTER the web form.

ParameterDescriptionRequired
varName of the JavaScript object createdno
attachToName of the JavaScript object to which toggle will attach. You must define 'var' for this to work.no
baseUrlURL of server-side action or servlet that processes a simple command from a toggle action; responds with a single option value and labelyes
sourceA unique ID for each toggle tagyes
ratingsComma-delimited list of rating valuesyes
defaultRatingThe default rating to use from the 'ratings' listyes
stateID of hidden form field used to hold the current stateyes
onOffWhether this is a simple on/off (two-value) rating [default=false]no
containerClassCSS style class for the container wrapping the toggleyes
messageClassCSS style class for the message displayed as you mouseover each toggle imageno
selectedClassCSS style class for the rating that's selectedyes
selectedLessClassCSS style class for the rating that is less than the selected one as you mouseoveryes
selectedOverClassCSS style class for the rating that is greater than the selected one as you mouseoveryes
overClassCSS style class for the rating that is greater than the selected oneyes
parametersA comma-separated list of parameters to pass to the server-side action or servletrating=ajaxParameter
preFunctionFunction to execute before Ajax is begunno
postFunctionFunction to execute after Ajax is finished, allowing for a chain of additional functions to executeno
errorFunctionFunction to execute if there is a server exception (non-200 HTTP response)no
parserThe response parser to implement [default=ResponseHtmlParser]no

ajax:updateField

Builds the JavaScript required to update one or more form fields based on the value of another single field.

<form>
  <fieldset>
  <legend>Velocity Conversion</legend>
  <label for="mph">Miles/Hour (mph)</label>
  <input type="text" id="mph" />
  <input id="action" type="button" value="Go"/>

  <label for="kph">Kilometers/Hour (kph)</label>
  <input type="text" id="kph" />

  <label for="mps">Meters/Second (m/s)</label>
  <input type="text" id="mps" />
  </fieldset>
</form>

<ajax:updateField
  baseUrl="${pageContext.request.contextPath}/ConvertMPH.view"
  source="mph"
  target="kph,mps"
  action="action"
  parameters="mph={mph}" />

Note: Tag must appear AFTER the web form.

ParameterDescriptionRequired
varName of the JavaScript object createdno
attachToName of the JavaScript object to which updateField will attach. You must define 'var' for this to work.no
baseUrlURL of server-side action or servlet that processes a simple commandyes
sourceThe form field that will hold the parameter passed to the servletyes
targetA comma-delimited list of form field IDs that will be populated with resultsyes
actionID of form button or image tag that will fire the onclick eventyes
parametersA comma-separated list of parameters to pass to the server-side action or servletno
eventTypeSpecifies the event type to attach to the source field(s)no
preFunctionFunction to execute before Ajax is begunno
postFunctionFunction to execute after Ajax is finished, allowing for a chain of additional functions to executeno
errorFunctionFunction to execute if there is a server exception (non-200 HTTP response)no
parserThe response parser to implement [default=ResponseHtmlParser]no

ajax:tree

Builds the JavaScript required to create a tree


<ajax:tree
        baseUrl="${contextPath}/tree.view"
        id="cars"
        parameters="node={ajaxParameter}"
        nodeClass="nodeClass"
        expandedClass="expandedNode"
        collapsedClass="collapsedNode"
        treeClass="tree">
</ajax:tree>

Note: The styleId value will be the first one sent to the baseUrl to get the nodes on the first level

ParameterDescriptionRequired
baseUrlURL of server-side action or servlet that processes a simple commandyes
actionID of form button or image tag that will fire the onclick eventyes
parametersA comma-separated list of parameters to pass to the server-side action or servletyes
idThe ID of the treeyes
preFunctionFunction to execute before Ajax is begunno
postFunctionFunction to execute after Ajax is finished, allowing for a chain of additional functions to executeno
errorFunctionFunction to execute if there is a server exception (non-200 HTTP response)no
parserThe response parser to implement [default=ResponseXmlToHtmlLinkListParser]no
collapsedClassCSS style class for the node's image(when collapsed)no
expandedClassCSS style class for the node's image(when expanded)no
treeClassCSS style class for the unsorted list(each node is hosted on one)no
nodeClassCSS style class for the node's linkno