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.
Bean Properties
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:
In order to simplify this, you can access the same property using the following expression:
Note: In situations where the field in the object is public, MVEL will still prefer to access the property via it's getter method.
Null-Safe Bean Navigation
Sometimes you have property expressions which may contain a null element, requiring you to create a null-check. You can simplify this by using the null-safe operator:
This is functionally equivalent to writing:
Collections
Traversal of collections can also be achieved using abbreviated syntax.
List Access
Lists are accessed the same as array's. For example:
is the equivelent of the Java code:
Map Access
Maps are accessed in the same way as array's except any object can be passed as the index value. For example:
is the equivelent of the Java code:
For Maps that use a String as a key, you may use another special syntax:
... Allowing you to treat the Map itself as a virtual object.
Strings as Arrays
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:
1 Comment
Hide/Show CommentsOct 24, 2008
Åge Gulbrandsen
Null-Safe Bean Navigation.
There are 3 object-levels which all may be null,
user may be null, manager may be null, and name may be null.
Is there only test on ?manager in the example? (I have never heard about MVEL before)