-
Notifications
You must be signed in to change notification settings - Fork 0
Property Navigation
MVEL property navigation follows well-established conventions found in other bean property expressions found in other languages such as Groovy, OGNL, EL, etc.
Unlike some other languages which require qualification depending on the underlying method of access, MVEL provides a single, unified syntax for accessing properties, static fields, maps, etc.
Most java developers are familiar with and user the getter/setter paradigm in their Java objects in order to encapsulate property accessors. For example, you might access a property from an object as such:
user.getManager().getName();
In order to simplify this, you can access the same property using the following expression:
user.manager.name
Note: In situations where the field in the object is public, MVEL will still prefer to access the property via it's getter method.
Traversal of collections can also be achieved using abbreviated syntax.
Lists are accessed the same as array's. For example:
user[5]
is the equivalent of the Java code:
user.get(5);
Maps are accessed in the same way as array's except any object can be passed as the index value. For example:
user["foobar"]
is the equivalent of the Java code:
user.get("foobar");
For Maps that use a String as a key, you may use another special syntax:
user.foobar
... allowing you to treat the Map itself as a virtual object.
For the purposes of using property indexes (as well as iteration) all Strings are treated as arrays. In MVEL you may refer to the first character in a String variable as such:
foo = "My String";
foo[0]; // returns 'M'
This is the documentation for MVEL 1.2.x and 1.3.x. If you are using MVEL 2.*, please proceed to the documentation for MVEL 2.*