...
A series of property names may be specified, separated by periods: "user.name
", which is equivalent to either getUser().getName()
or getUser().setName()
, depending on context (whether the expression is being read or updated).
The "." is called the "dereference operator". In addition, there is a a "safe dereference operator", "?.", which works the same as "." except that it allows any of the properties to be null. When reading, a null short-circuits the expression (which returns null). When writing to a property, an intermediate null value will cause the value to be discarded without error.
In other words, "user?.name" works, even when the user
property may be null.
...
Property expressions are compiled to Java classes at runtime; there is no runtime reflection (unlike the OGNL expression language used in prior releases of Tapestry 4 and earlier).
Grammar
Expressed in simplified Backus–Naur Form, the grammar of property expressions is as follows:
...
| Example | Notes |
---|---|---|
Keyword | this |
|
Keyword | null |
|
Property Name | userName | Calls getUserName() or setUserName, depending on context |
Property Chain | user.address.city | Calls getUser().getAddress().getCity() or getUser().getAddress().setCity(), depending on context |
Property Chain | user?.name | Calls getUser() and, if the result is not null, calls getName() on the result |
Method Invocation | groupList.size() | calls getGroupList().size() |
Method Invocation | members.findById(user.id)?.name | Calls getMembers().findById(getUser().getId())?.getName() (unless findById returns null) |
Range | 1..10 | Iterates between integers 1 and 10 |
Range | 1..groupListmyList.size() | Iterates between 1 and the result of getGroupListgetMyList().size() |
Literal String | 'Beer is proof that God loves us and wants us to be happy.' | Use single quotes |
List | [user.name, user.email, user.phone] |
|
Not Operator | ! user.deleted | the boolean negation of getUser().getDeleted() |
Not, Coerced | ! user.middleName | true only if getUser.getMiddleName() returns null or an empty string |
Map | { 'framework' : 'Tapestry', 'version' : version } | Keys are string literals (in single quotes), but could be properties as well |
Scrollbar |
---|