|
|||||
|
|||||
Useful Things |
MVEL 2.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. Bean PropertiesMost 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:
Null-Safe Bean NavigationSometimes 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: CollectionsTraversal of collections can also be achieved using abbreviated syntax. List AccessLists are accessed the same as array's. For example: is the equivelent of the Java code: Map AccessMaps 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 ArraysFor 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: |
||||
|
Copyright 2003-2006 - The Codehaus. All rights reserved unless otherwise noted.
Powered by Atlassian Confluence
|
|||||