Operand Coercing Rules
Before the operator is applied, the EL evaluator coerces the types of the operand values. An exception is thrown if no rule matches, the coercing fails, or applying the operator leads to an exception.
Property and array accessor operators
An expression of the form
${exprA.identifierB}
is evaluated the same way as
${exprA['identifierB']}
.
To evaluate an expression of the form
${exprA[exprB]}
, the following rules are used:
If
exprA
isnull
, returnnull
.If
exprB
isnull
, returnnull
.If
exprA
is aMap
with a key matchingexprB
, return the value.If
exprA
is aList
or array with an index matchingexprB
coerced to anint
, return the value.If
exprA
is a bean with a property matchingexprB
coerced to aString
, return the value.
Arithmetic operators
For addition, subtraction, and
multiplication, if any operand is null
, the result
is 0. Otherwise both operands are coerced to numbers (to
BigDecimal
if one of them is
BigDecimal
or if one is
BigInteger
and the other is
Float
, Double
, or a
String
with floating-point syntax, to
double
if one of them is Float
,
Double
, or a String
with
floating-point syntax, to BigInteger
if one of
them is BigInteger
, to long
otherwise), and the result of applying the operator is returned.
For division, if any operand is null
, the result
is 0. Otherwise both operands are coerced to numbers (to
BigDecimal
if one of them is
BigInteger
or BigDecimal
, to
double
otherwise), and the result of applying the
operator is returned.
For modulo, if any operand ...
Get JavaServer Pages, 3rd 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.