dsp:test
takes an object input and produces an object named by the var
-specified EL 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).
Attributes
TagVariable:varorid(Required)
You must define an EL variable or scripting variable:
Attribute | Description |
---|---|
| Names an EL variable. When you use |
| Names a scripting variable, which scriptlets and expressions can access at runtime. |
VariableScope:scope
The scope
attribute determines what resources can access the named EL variable. Options include: page
, request
, session
, or application
. Omitting this attribute causes the default, page
, to be used.
ObjectInput:value(Required)
The value
attribute holds a Collection, an array, or a Map that is passed to the object referenced by the EL variable.
Properties
nullValue
The nullValue
property evaluates whether the object held by the value
attribute has a value of 0
. A call to isNull
returns true when the contents are zero and false under any other circumstances.
array
The array
property evaluates whether the object held by the value
attribute is an array. A call to isArray
returns true when the item is an array and false when it is not.
collection
The collection
property evaluates whether the object held by the value
attribute is a Collection. A call to isCollection
returns true when the item is a Collection and false when it is not.
arrayOrCollection
The arrayOrCollection
property evaluates whether the object held by the value
attribute is an array or a Collection. A call to isArrayOrCollection
returns true when the item is an array or Collection and false when it is not either data type.
size
The size
property evaluates the size of the object held by the value
attribute. A call to isSize
returns the following:
For array, Collection, Map, or Enumeration objects, returns the actual object size.
For String objects, returns the length of the String.
For all other objects, returns
1
.
emptyValue
The emptyValue
property evaluates whether the object held by the value
attribute has a value. A call to isEmpty
returns the following:
For array, Collection, Iterator, Map, or Enumeration objects, returns true when the object has 0 or no objects.
For String objects, returns true when String is empty or the value is
null
.Otherwise, returns false.
valueClass
The valueClass
property identifies the class of the object identified by the value
attribute. When the value
attribute is set to null
, the valueClass
returns null
.
hashcode
The hashcode
property renders the hash code associated with the object identified in the value
attribute. A call to isHashCode
when no hash code exists or the hash code is 0 returns null
.
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.