Dynamically generating HTML from a java object is a
very common requirement for most applications. The droplet
tag will help us in this by embedding the ATG servlet beans.
The output of the ATG servlet beans is included in the HTML page. In
this article our prime focus will be on a simple ATG Out of
the Box servlet bean.
DSP:DROPLET tag: helps you invoke a
servlet bean from a JSP page. The programming logic will be
encapsulated in a java class(bean) which is used in the jsp.
ForEach Droplet:
(”atg.droplet.ForEach” is the class, Component is
“atg/dynamo/droplet/ForEach”) help us to iterate through the
elements of an array which we specify. The droplet helps us to
specify the HTML before and after the array processing also to
specify the HTML if the array is empty.
<dsp:droplet
name="/atg/dynamo/droplet/ForEach">
<dsp:param name="array" bean="/Employee.technologies"/>
<dsp:oparam name="outputStart">
<p>Employee and corresponding technologies</p>
</dsp:oparam>
<dsp:oparam name="output">
<li><dsp:valueof param="element"></dsp:valueof></li>
</dsp:oparam>
<dsp:oparam name="outputEnd">
<p>List finished</p>
</dsp:oparm>
</dsp:droplet>
<dsp:param name="array" bean="/Employee.technologies"/>
<dsp:oparam name="outputStart">
<p>Employee and corresponding technologies</p>
</dsp:oparam>
<dsp:oparam name="output">
<li><dsp:valueof param="element"></dsp:valueof></li>
</dsp:oparam>
<dsp:oparam name="outputEnd">
<p>List finished</p>
</dsp:oparm>
</dsp:droplet>
Here “Employee” is a bean and “technologies”
is returning a set of values(various technlogies the particular
employee know).Say atg,java,jsp,javascripts.
The output will be like:
Employee and corresponding technologies
atg
java
jsp
javascripts
List finished
INPUT PARAMETERs in the droplet:The output will be like:
Employee and corresponding technologies
atg
java
jsp
javascripts
List finished
1. array: parameter can be a collection, enumeration, Iterator, map or array.
2. sortProperties
This is an optional parameter and holds a string that specifies the order the items in the array are rendered.
A + and – will sort the properties in acsending and descending order respectively. The Syntax varies depending on the type of item in the array,
- If its a JavaBean specify the sortProperties in a comma seperated list of property names.
- If the array constitutes a Strings, numbers or dates; just mention a + or -
- While sorting values of a map and we have to sort according to the key, give “_key” along with +/- to indicate the sort order.
Eg: (in the above order)
<dsp:param name="sortProperties" values="+name, - age"/> (This will sort first by an alphabetical ordering of name and then by descending order of age.)
<dsp:param name="sortProperties" values="+"/>
<dsp:param name="sortProperties" values="+_key"/>
No comments:
Post a Comment