Sets a variable to reference a Collection, array, or Map in order to test its properties.
<dsp:testvar-spec
value=value-spec
/>
Attributes
var-spec
An EL variable or scripting variable that is set to the object to test, defined with one of these attributes:
Attribute | Description |
---|---|
| Names an EL variable. When you use The EL variable has a number of properties that you can query—for example, the referenced object’s size or number of items. For information on available properties, see Usage Notes below. |
| Names a scripting variable that scriptlets and expressions can access at runtime. |
value
Sets the specified variable to a Collection, array, or Map.
Usage Notes
dsp:test
takes an object input and produces an object named by the specified variable. Other tags can query the object to find out information about the original input object, such as its size (empty, null, or number of items).
The following properties and runtime methods are available:
Property/Method | Description |
---|---|
| Returns true if the tested object has a value of |
| Returns true if the tested object is an array. |
| Returns true if the tested object is a Collection. |
| Returns true if the tested object is an array or Collection. |
| Tests the size of the object, returns one of the following: - Array, Collection, Map, or Enumeration objects: the object size. - String objects: the String length. - All other objects: |
| Tests whether the object has a value, returns one of the following: - Array, Collection, Iterator, Map, or Enumeration objects: true if the object has zero or no objects. - String objects: true if the String is empty or the value is |
| Identifies the class of the tested object, returns |
| Renders the tested object’s hash code. returns |
Example
<dsp:tomap bean="Articles.current" var="currentArticles"/>
<dsp:test var="objectSize" value="${currentArticles}"/>
Total article count for this week should be 10. We have
<c:out value="${objectSize.size}"/> articles.
In this example, the current property of the Articles
component is passed through the dsp:test
tag. The object referenced by the EL variable objectSize
holds information about Articles.current
and so a call to its size
property returns the size of the current
array.