ClassName

atg.droplet.Range

Component

/atg/dynamo/droplet/Range

The Range servlet bean is similar to the ForEach servlet bean, except that it enables you to render a subset of the output array, rather than the entire array. Range renders its output parameter for each element in its array parameter, beginning with the array element that corresponds to the start parameter and continuing until it has rendered a number of elements equal to the howMany parameter. The array parameter can be a Collection (Vector, List, or Set), Iterator, Enumeration, Map, Dictionary, or array.

Input Parameters

array
Defines the list of items to output. This parameter can be a Collection (Vector, List, or Set), Iterator, Enumeration, Map, Dictionary, or array.

howMany
Specifies the number of items in the array to display. If the combination of start and howMany points past the end of the array, Range stops rendering when the end of the array is reached.

start
Specifies which element of the array to start with. Setting start=1 renders the array beginning with its first element. If start is greater than the number of elements in the array and the empty output parameter is supplied in your implementation, the empty parameter is rendered.

sortProperties
This optional parameter holds a string that specifies the order the items in the array are rendered. The syntax of this parameter depends on the type of item in the array: JavaBeans, Dynamic Beans, or on Dates, Numbers, or Strings.

To sort on the properties of a JavaBean, specify the value of sortProperties as a comma-separated list of property names. You can sort on as many properties as you like. The first property name specifies the primary sort, the second property name specifies the secondary sort, and so on. Use + followed by a property name to indicate that items in the array should be sorted in ascending order and followed by the property name to indicate descending order.

For example, to sort an array of JavaBeans first by an alphabetical ordering of title and then by descending order of size, use this input parameter:

<dsp:param name="sortProperties" value="+title,size"/>

If your array consists of Dates, Numbers, or Strings, specify the value of sortProperties with either a single + or a single to indicate ascending or descending order respectively.

For example, to sort an output array of Strings in alphabetical order:

<dsp:param name="sortProperties" value="+"/>

When you are sorting elements of a Map, and you want to sort by the key, set the value to the ascending/descending indicator followed by an underscore and the term key:

<dsp:param name="sortProperties" value="_key"/>

When one servlet bean is nested in another and both accept the sortProperties parameter, the child servlet bean inherits the sortProperties setting applied by the enclosing servlet bean unless the child specifies another sortProperties setting or is assigned an empty value:

<dsp:param name="sortProperties" value=""/>

Output Parameters

index
The zero-based index of the current element of the array each time that the output parameter is rendered. For example, if start is set to 1, the value of index for the first iteration is 0.

count
The one-based index of the current element of the array each time that the output parameter is rendered. For example, if start is set to 1, the value of count for the first iteration is 1.

key
If the array parameter is a Map or Dictionary, this parameter is set to the value of the key in the Map or Dictionary.

element
The current element of the array each time that the index increments and the output parameter is rendered.

size
The total number of items in the source array.

end
When the result set is divided into subsets, this parameter causes the last element in a subset to display its numbered value. This parameter uses a 1-based count.

hasPrev
This parameter is set to true before any of the output parameters are rendered. It indicates whether the array includes any items that precede the current array set.

prevStart
This parameter is set before any of the output parameters are rendered and only if hasPrev is true. It indicates the value of start that should be used to display the previous array set. You can use this parameter to create a link or form submission that displays the previous elements of the array.

prevEnd
This parameter is set before any of the output parameters are rendered, and only if hasPrev is true. It indicates the (1-based) count of the last element in the previous array set.

prevHowMany
This parameter is set before any of the output parameters are rendered, and only if hasPrev is true. It indicates the number of elements in the previous array set.

hasNext
This parameter is set to true before any of the output parameters are rendered. It indicates whether the array includes any items that follow the current array set.

nextStart
This parameter is set before any of the output parameters are rendered, and only if hasNext is true. It indicates the value of start that should be used to display the next array set.

nextEnd
This parameter is set before any of the output parameters are rendered, and only if hasNext is true. It indicates the (1-based) count of the last element in the next array set.

nextHowMany
This parameter is set before any of the output parameters are rendered, and only if hasNext is true. It indicates the number of elements in the next array set.

Open Parameters

output
This parameter is rendered once for each element in the subset of the array defined by the start and howMany parameters.

outputStart
If the array is not empty, this parameter is rendered before any output elements. It can be used to render a heading, for instance.

outputEnd
If the array is not empty, this parameter is rendered after all output elements. It can be used to render a footer, for instance.

empty
This optional parameter is rendered if the array or the specified subset of the array contains no elements.

Example

This example displays the values of the initialServices property of ATG’s Initial component. The values are displayed 2 at a time. This example uses a Switch servlet bean to create navigational links after each 2 values. If there are values in the array that precede the ones currently displayed, there is a link to the previous values. If there are values in the array that follow the ones currently displayed, there is a link to the next set of values.

<dsp:importbean bean="/atg/dynamo/droplet/Range"/>
<dsp:importbean bean="/atg/dynamo/droplet/Switch"/>

<dsp:droplet name="Range">
  <dsp:param bean="/Initial.initialServices" name="array"/>
  <dsp:param name="howMany" value="2"/>
  <dsp:oparam name="outputStart"><h3>Initial Services:</h3><ul></dsp:oparam>
  <dsp:oparam name="outputEnd">
    </ul>
    <dsp:droplet name="Switch">
      <dsp:param name="value" param="hasPrev"/>
      <dsp:oparam name="true">
        <dsp:getvalueof var="a27" bean="/OriginatingRequest.pathInfo"
        idtype="java.lang.String">
          <dsp:a href="${a27}">
            <dsp:param name="start" param="prevStart"/>
            Previous <dsp:valueof param="prevHowMany"/>
          </dsp:a>
        </dsp:getvalueof>
      </dsp:oparam>
    </dsp:droplet>
    &nbsp;
    <dsp:droplet name="Switch">
      <dsp:param name="value" param="hasNext"/>
      <dsp:oparam name="true">
        <dsp:getvalueof var="a46" bean="/OriginatingRequest.pathInfo"
        idtype="java.lang.String">
          <dsp:a href="${a46}">
            <dsp:param name="start" param="nextStart"/>
            Next <dsp:valueof param="nextHowMany"/>
          </dsp:a>
        </dsp:getvalueof>
      </dsp:oparam>
    </dsp:droplet>
  </dsp:oparam>
  <dsp:oparam name="output">
    <li><dsp:valueof param="element.absoluteName">&nbsp;</dsp:valueof>
  </dsp:oparam>
</dsp:droplet>
 
loading table of contents...