Property ExpressionsPage edited by Bob Harner
Comment:
Added "Examples" section (SOMEBODY PLEASE REVIEW AND ADD TO THIS!), and added reference to Backus–Naur Form
Changes (5)
Full ContentProperty ExpressionsTapestry uses property expressions to move data between components. Property expressions are the basis of the component parameters and template expansions. A property _expression_ is a string that explains to Tapestry how to navigate from a root object (the containing component) through some number of properties, to a final property that can be read or updated. As elsewhere in Tapestry, the names of properties and methods are recognized in a case-insensitive manner. The most basic form of a property _expression_ is a simple property name, such as "userName". 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. The "." is called the "dereference operator". A second operator is "?." or the "safe dereference operator". This 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 can also reference public methods. Methods may take parameters (or not), but must not return void. When the final term in a property _expression_ is a method, then the property _expression_ is read-only. Being able to invoke methods was originally added so that it was possible to access methods such as java.util.Map.size() (which is not named like a property getter method). In Tapestry 5.1, property expressions were extended so that parameters could be passed into methods. Parameters to methods are, themselves, property expressions. This means that you can write a property _expression_ that reads a property and passes it as a parameter to a method, and then access a property of the object returned from the method. CompilationProperty expressions are compiled to Java classes at runtime; there is no runtime reflection (unlike the OGNL _expression_ language used in prior releases of Tapestry). GrammarExpressed in simplified Backus–Naur Form, the grammar of property expressions is as follows: _expression_ : keyword | rangeOp | constant | propertyChain | list | notOp; keyword : 'null' | 'this'; constant : 'true' | 'false' | <integer> | <decimal> | <string>; rangeOp : rangeOpArg '..' rangeOpArg; rangeOpArg : <integer> | propertyChain; propertyChain : term '.' propertyChain | term '?.' propertyChain | term; term : <identifier> | <identifier> '(' expressionList? ')'; list : '[' expressionList? ']'; expressionList : _expression_ (',' _expression_)*; notOpt : '!' _expression_; Notes:
Examples
Change Notification Preferences
View Online
|
View Changes
|
- [CONF] Apache Tapestry > Property Expressions confluence