Sets a variable to reference a Collection, array, or Map in order to test its properties.

<dsp:test var-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

var

Names an EL variable. When you use var, you can set its scope attribute to page, request, session, or application. The default scope is page. For more information, see EL Variable Scopes.

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.

id

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

nullValue
isNull

Returns true if the tested object has a value of 0.

array
isArray

Returns true if the tested object is an array.

collection
isCollection

Returns true if the tested object is a Collection.

arrayOrCollection
isArrayOrCollection

Returns true if the tested object is an array or Collection.

size
isSize

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: 1

emptyValue
isEmpty

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 null.

valueClass

Identifies the class of the tested object, returns null if the value attribute is set to null.

hashcode
isHashCode

Renders the tested object’s hash code. returns null if no hash code exists or the hash code is 0.

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.