Category | Operators |
Variable | .and [] |
Arithmetic | +,-(binary), *, / and div, %and mod,-(unary) |
Logical | and, &&, or,||,not,! |
Relational | ==, eq, !=, ne, <, lt, >, gt, <=, le, >=, ge |
Conditional | A ? B : C |
Empty/Null checking | empty |
${objectName.propertyName}
${mapObject.keyName}
For example:
${param.username}
${header.host}
${userBean.email}
The [] operator does same thing as the . operator, however, it can be also used to access elements of an array or a list by specifying an index. For example:${param["username"]}
${header["host"]}
${userBean["email"]}
${jobTitles["1"]}
${listUsers[1].email}
It’s also possible to access nested property like this:${userBean.currentJob.title}
Operator | Meaning | EL Expression Example | Result |
+ | Addition | ${100 + 200} | 300 |
- (binary) | Subtraction | ${100 - 200} | -100 |
* | Multiplication | ${9 * 9} | 81 |
/ or div | Division | ${200 / 100} ${200 div 100} ${200 / 0} | 2.0 2.0 Infinity |
% or mod | Remainder | ${2013 % 100} ${2013 mod 100} ${200 mod 0} | 13 13 Exception |
- (unary) | Negation | ${-20} ${20 - (-20)} | -20 40 |
${200 mod 0}
Then this exception will be thrown:java.lang.ArithmeticException: / by zero
Also note that in an arithmetic expression, a null is treated as zero. For example in the following expression:${user.age + 50}
If the variable user or age evaluates to null, then result of the expression is 50.Operator | Meaning | EL Expression Example | Result |
and, && | Logical AND | ${true && false} ${false and false) | false false |
or, || | Logical OR | ${true || false} ${false or false} | true false |
not, ! | Unary boolean complement | ${!false} ${!true} | true false |
${user.logged && true}
If the variable user or logged evaluates to null, then result of the expression is false.Operator | Meaning | EL Expression Example | Result |
==, eq | Equality test | ${100 == 100} ${101 eq 102} | true false |
!=, ne | Un-equality test | ${100 != 200} ${200 ne 200} | true false |
<, lt | Less than test | ${9 < 10} ${9 lt 8} | true false |
>, gt | Greater then test | ${10 > 9} ${10 gt 20} | true false |
<=, le | less than or equal test | ${100 <= 200} ${100 le 100} | true true |
>=, ge | greater than or equal test | ${100 >= 200} ${100 ge 100} | false true |
A ? B : C
If A evaluates to true, then evaluate B, else evaluate C. For example:${(8 + 9) > 10 ? (11 + 12) : (13 + 14) }
Result: 23${empty value}
It returns true if value is null or empty, and returns false otherwise. For example:${empty param.username}
The above expression returns true if the parameter username is null or a empty String. Another example:${empty listUsers}
The variable listUsers is an ArrayList, the expression returns true if the list has no element (empty).EL Expression Example | Result |
${2 * 4 + 3 * 4} | 20 |
${8 + 10 / 5 - 3} | 7 |
${5 > 3 && 4 > 6} | false |
${1 + 2 > 3 ? 4 * 5 : 6 - 7} | -1 |