Data Types
A variable is
always
of a specific Java type. In addition to the standard Java types for
numeric, Boolean, and text values, the EL provides special support
for custom classes developed according to the JavaBeans guidelines,
java.util.Map
object,
java.util.List
objects, and arrays.
Bean properties can be accessed using the special property accessor operator (a dot) and be nested to any length:
${aBean.aProperty.aPropertyOfTheProperty.andSoOn}
Map
entries can
be
accessed the same way:
${aMap.aKey}
List
and array
elements can be accessed using the
array accessor operator (square
brackets):
${aList[0]} ${anArray[0]} ${anArrayOrList[anExressionWithANumbericValue]}
The array accessor operator can also access bean properties and
Map
entries when the property name must be
composed by an expression, or the property name is a reserved word or
contains characters used for operators:
${aMap[param.customerName]} ${aBean['empty']} ${aMap['com.mycomp.logo']}
Coercion Rules
The EL automatically converts, or coerces, variable values and the result of an expression to the type required by an attribute or an operator:
To Java type |
Conversion rule |
---|---|
String |
All other types: to the corresponding |
Primitive number or |
Numeric types: coerce to the requested precision. |
|
|
Get JavaServer Pages, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.