Provides an API for using EL in a stand-alone environment.
This class provides a direct and simple interface for
- Evaluating EL expressions.
- Assigning values to beans or setting a bean property.
- Setting a {@link ValueExpression} to a EL variable.
- Defining a static method as an EL function.
- Defining an object instance as an EL name.
This API is not a replacement for the APIs in EL 2.2. Containers that maintains EL environments can continue to do so, without using this API.
For EL users who want to manipulate EL environments, like adding custom {@link ELResolver}s, {@link ELManager} can be used.
Scope and Life Cycle
Since it maintains the state of the EL environments, ELProcessor
is not thread safe. In the simplest case, an instance can be created and destroyed before and after evaluating EL expressions. A more general usage is to use an instance of ELProcessor
for a session, so that the user can configure the EL evaluation environment for that session.
Automatic Bracketing of Expressions
A note about the EL expressions strings used in the class. The strings allowed in the methods {@link ELProcessor#getValue}, {@link ELProcessor#setValue}, and {@link ELProcessor#setVariable} arelimited to non-composite expressions, i.e. expressions of the form ${...} or #{...} only. Also, it is not necessary (in fact not allowed) to bracket the expression strings with ${ or #{ and } in these methods: they will be automatically bracketed. This reduces the visual cluster, without any lost of functionalities (thanks to the addition of the concatenation operator).
Example
The following code snippet illustrates the use of ELProcessor to define a bean and evaluate its property.
ELProcessor elp = new ELProcessor(); elp.defineBean("employee", new Employee("Charlie Brown")); String name = elp.eval("employee.name");
@since EL 3.0