Class ELProcessor
java.lang.Object
jakarta.el.ELProcessor
Provides a simple API for evaluating EL expressions in a standalone environment. This class wraps an
ELManager and provides methods for evaluating expressions, defining beans and functions, and managing
variables. It is the primary entry point for applications that use the EL API outside of a Jakarta EE container.- Since:
- EL 3.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddefineBean(String name, Object bean) Defines or removes a bean accessible by name in EL expressions.voiddefineFunction(String prefix, String function, Method method) Map a method to a function name.voiddefineFunction(String prefix, String function, String className, String methodName) Registers a function in the EL context by looking up the static method in the given class.<T> TEvaluates the given EL expression and returns the result as the requested type.Returns theELManagerthat manages the EL context, resolvers, functions, and variables for this processor.<T> TEvaluates the given EL expression and returns the result coerced to the expected type.voidEvaluates the given EL expression and sets the result to the specified value.voidsetVariable(String variable, String expression) Registers a variable in the EL context.
-
Constructor Details
-
ELProcessor
public ELProcessor()Constructs an ELProcessor with a defaultELManagerandStandardELContext. The processor is ready to evaluate expressions immediately after construction.
-
-
Method Details
-
getELManager
-
eval
Evaluates the given EL expression and returns the result as the requested type. The expression is automatically wrapped in ${} delimiters before evaluation.- Type Parameters:
T- the expected result type- Parameters:
expression- the EL expression to evaluate- Returns:
- the result of evaluating the expression, coerced to the requested type
- Throws:
ELException- if the expression cannot be evaluated
-
getValue
Evaluates the given EL expression and returns the result coerced to the expected type. The expression is automatically wrapped in ${} delimiters before evaluation.- Type Parameters:
T- the expected result type- Parameters:
expression- the EL expression to evaluateexpectedType- the class of the expected result type- Returns:
- the result of evaluating the expression, coerced to the expected type
- Throws:
ELException- if the expression cannot be evaluated
-
setValue
Evaluates the given EL expression and sets the result to the specified value. This is used for EL assignment expressions. The expression is automatically wrapped in ${} delimiters before evaluation.- Parameters:
expression- the EL expression to evaluatevalue- the value to assign- Throws:
ELException- if the expression cannot be evaluated or the target is not writable
-
setVariable
Registers a variable in the EL context. The variable is associated with the result of evaluating the given expression. Passing anullexpression removes the variable from the context.- Parameters:
variable- the variable nameexpression- the EL expression to associate with the variable, ornullto remove- Throws:
ELException- if the expression cannot be evaluated
-
defineFunction
public void defineFunction(String prefix, String function, String className, String methodName) throws ClassNotFoundException, NoSuchMethodException Registers a function in the EL context by looking up the static method in the given class. The method name may include a return type and parameter signature in the formatreturnType methodName(paramTypes). The function is then callable in EL expressions asprefix:function(args).- Parameters:
prefix- the namespace prefix for the functionfunction- the local function name, or empty to use the method nameclassName- the fully qualified name of the class containing the static methodmethodName- the method name, optionally with return type and parameter signature- Throws:
ClassNotFoundException- if the class cannot be found or is not publicNoSuchMethodException- if the method cannot be found or is not a public static method
-
defineFunction
public void defineFunction(String prefix, String function, Method method) throws NoSuchMethodException Map a method to a function name.- Parameters:
prefix- Function prefixfunction- Function namemethod- Method- Throws:
NullPointerException- If any of the arguments are nullNoSuchMethodException- If the method is not static
-
defineBean
Defines or removes a bean accessible by name in EL expressions. When a non-null bean is provided, it is stored under the given name. Whennullis provided, the bean with the given name is removed.- Parameters:
name- the bean namebean- the bean object to define, ornullto remove the bean
-