Table of Contents
This section has a fairly detailed treatment of OGNL's syntax and implementation. See below for a complete table of OGNL's operators, a section on how OGNL coerces objects to various types, and a detailed description of OGNL's basic expressions.
OGNL borrows most of Java's operators, and adds a few new ones. For the most part, OGNL's treatment of a given operator is the same as Java's, with the important caveat that OGNL is essentially a typeless language. What that means is that every value in OGNL is a Java object, and OGNL attempts to coerce from each object a meaning appropriate to the situation it is used in (see the section on coercion).
The following table lists OGNL operators in reverse precedence order. When more than one operator is listed in the same box, these operators have the same precedence and are evaluated in left-to-right order.
Table A.1. OGNL Operators
Operator | getValue() Notes | setValue() Notes | |||
---|---|---|---|---|---|
| Both e1 and e2 are evaluated with the same source object, and the result of e2 is returned. | getValue is called on e1 , and then setValue is called on e2 . | |||
| getValue is called on e2 , and then setValue is called on e1 with the result of e2 as the target object. | Cannot be the top-level expression for setValue . | |||
| getValue is called on e1 and the result is interpreted as a boolean. getValue is then called on either
e2 or e3 , depending on whether the result of e1 was true or false respectively, and the result is returned. | getValue is called on e1 , and then setValue is called on either e2 or e3 . | |||
| getValue is called on e1 and the result is interpreted as a boolean. If true , that result is returned;
if false , getValue is called on e2 and its value is returned. | getValue is called on e1 ; if false , setValue is called on e2 . Note that e1 being
true prevents any further setting from taking place. | |||
| getValue is called on e1 and the result is interpreted as a boolean. If false , that result is returned;
if true, getValue is called on e2 and its value is returned. | getValue is called on e1 ; if true , setValue is called on e2 . Note that e1 being
false prevents any further setting from taking place. | |||
| e1 and e2 are interpreted as integers and the result is an integer. | Cannot be the top-level expression passed to setValue . | |||
| e1 and e2 are interpreted as integers and the result is an integer. | Cannot be the top-level expression passed to setValue . | |||
| e1 and e2 are interpreted as integers and the result is an integer. | Cannot be the top-level expression passed to setValue . | |||
| Equality is tested for as follows. If either value is null , they are equal if and only if both are null . If they are the same object or the
equals() method says they are equal, they are equal. If they are both Number s, they are equal if their values as double-precision floating point numbers are equal. Otherwise,
they are not equal. These rules make numbers compare equal more readily than they would normally, if just using the equals method. | Cannot be the top-level expression passed to setValue . | |||
| The ordering operators compare with compareTo() if their arguments are non-numeric and implement Comparable ; otherwise, the arguments are interpreted as
numbers and compared numerically. The in operator is not from Java; it tests for inclusion of e1 in e2, where e2 is interpreted as a collection. This test is not efficient: it iterates the collection. However, it uses the
standard OGNL equality test. | Cannot be the top-level expression passed to setValue . | |||
| e1 and e2 are interpreted as integers and the result is an integer. | Cannot be the top-level expression passed to setValue . | |||
| The plus operator concatenates strings if its arguments are non-numeric; otherwise it interprets its arguments as numbers and adds them. The minus operator always works on numbers. | Cannot be the top-level expression passed to setValue . | |||
| Multiplication, division, which interpret their arguments as numbers, and remainder, which interprets its arguments as integers. | Cannot be the top-level expression passed to setValue . | |||
| Unary plus is a no-op, it simply returns the value of its argument. Unary minus interprets its argument as a number. Logical not interprets
its argument as a boolean. Bitwise not interprets its argument as an integer. The class argument to instanceof is the fully qualified name of a Java
class. | Cannot be the top-level expression passed to setValue . | |||
| Generally speaking, navigation chains are evaluated by evaluating the first expression, then evaluating the second one with the result of the first as the source object. | Some of these forms can be passed as top-level expressions to setValue and others cannot. Only those chains that end in property references (e.property), indexes (e1[e2] ),
and subexpressions (e1.(e2) ) can be; and expression evaluations can be as well. For the chains, getValue is called on the left-hand expression (e or
e1 ), and then setValue is called on the rest with the result as the target object. | |||
| Basic expressions | Only property references (property ), indexes ([e] ), and variable references (#variable ) can be passed as top-level expressions to
setValue . For indexes, getValue is called on e , and then the result is used as the property "name" (which might be a String or any
other kind of object) to set in the current target object. Variable and property references are set more directly. | |||
|