EL Expressions
The syntax of an EL expressions is ${expr}. For example,
<element attr1="${bean.property}".../>
${map[entry]}
<another-element>${3+counter} is ${empty map}</another-element>
When an EL expression is used as an attribute value, it could return any kind of objects as long as the component accepts it. For example, the following expression will be evaluated as a Boolean object.
<window if="${some > 10}">
Associate with Java
There are several ways to associate Java objects with EL expressions.
- Implement a variable resolver (org.zkoss.xel.VariableResolver) and specify it with the variable-resolver directive.
- Return the object in a static method and specify it in the xel-method
- Declare multiple static methods in a taglib and declare it in taglib
- Construct them in zscript
Here is the detailed information for each feature. For introductory, please refer to ZK Developer’s Reference.
Lambda Expressions
since 8.0.0
ZK 8 supports lambda expressions in EL, allowing for anonymous functions within ZUL.
<textbox value="@load((x -> (x * 100) / 2.54)(vm.value))"
onOK="@command('click', key=((x -> (x * 2.54) / 100)(self.value)))" />
A lambda expression can also be named and evaluated later using the assignment and semicolon operators:
<label value="@load((incr = x -> x + 1; incr(5)))" />
Collection Operations
since 8.0.0
EL 3 allows direct use of collection chain operations and streaming API.
<listbox model="@load((vm.names.stream().filter(x -> x.contains(vm.filter)).toList()))">
You can also construct collections directly in an expression:
<label value="@load(([1, 2, 3, 4].stream().sum()))" />