Menu

toString

Creates a new variable holding a String that is created out of a specified value. This command has special handling for Collection values, presenting them as comma-separated lists with a specific property representing each of the Collection's items.

Attributes

var

Required
Value type
EL-evaluated
Yes String No
Defines the name of the variable holding the produced String.
value

Required
Value type
EL-evaluated
Yes Any Yes
Defines the value from which a String is produced out of. 
expr

Required
Value type
EL-evaluated
No String No
Defines the EL-expression used to produce a String representation out of the value that the value attribute resolves into.

If the resolved value is a Collection, then this expression is evaluated for every item in the Collection. The item can appear in the expression represented by the variable name defined in itemName. The results of these evaluations then appear in the Collection's String form separated by commas.

If the resolved value is not a Collection, then this expression is evaluated with that value being the variable behind the name defined in itemName.

If this attribute is undefined, Collection items and other values are directly converted into Strings. Note that certain kinds of more complex values convert into descriptor Strings that are generally not very suitable for any use - with such values defining a proper expression for this attribute is highly recommended. 
itemName

Required
Value type
EL-evaluated
No String Yes
This attribute can be used to specify the name of the variable representing the item in the EL-expression specified in expr.

If left undefined, the name of the item variable will be "x".

Examples

The toString command can produce a text representation of any value, but its primary feature is its ability to easily create text representations of Collections.

<toString var="contactNames" value="${contacts}" itemName="contact" expr="${contact.Name}">

This would produce a String listing the names of all contacts in the Collection, separated with commas.

Comments

0 comments