Java Reference
In-Depth Information
The employee makes more than 50,000:
#{elExampleManagedBean.displayResult(x -> x.wage gt 50000)}
Next, you'll take a look at the
eLExampleManagedBean.displayResult
method, which accepts
a
javax.el.LambdaExpression
as a parameter.
public boolean displayResult(javax.el.LambdaExpression le){
Employee e = new Employee(); // Grab an employee instance
if (le.invoke(e)){
return true;
} else {
return false;
}
}
Collections Enhancements
Collections have been reworked for EL 3.0, bringing them more in line with Java SE 8. Collections (sets, maps, and
lists) can be constructed dynamically in EL. EL collections can be constructed from literals or from EL expressions.
This can be a huge advantage when dynamically constructing a collection. In this section, I will briefly cover examples
for creating and using each type of collection.
Sets
Sets are surrounded by curly braces, as in
{}
, and elements of the set are separated by commas. The following are
examples of
Set
objects:
{a, b, c}
{1, "two", 3}
{a * b, 3, 5 * c}
Maps
Maps are key-value pairs, just like in the Java language. They are surrounded by curly braces, as in
{}
, just like
Set
objects. In a
Map
element, a colon is used to separate the key from the value. The following are examples of
Map
objects:
{"one":1, "two":2, 3:"three"}
{"first":"Josh", "last":"Juneau}
Lists
Lists are very similar to
Set
objects, but they have a different syntax because they are enclosed by brackets,
[]
, rather
than braces. The following are examples of
List
objects:
[a, b, c]
[1, "two", 3]
[d, [e, f, g, h], x]