Class ELManager
java.lang.Object
jakarta.el.ELManager
Provides a simplified API for managing EL context, resolvers, functions, and variables. This class maintains a
StandardELContext and provides convenience methods for adding resolvers, mapping functions, setting
variables, and managing imports. It is used internally by ELProcessor.- Since:
- EL 3.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBeanNameResolver(BeanNameResolver beanNameResolver) Adds aBeanNameELResolverto the resolver chain that uses the givenBeanNameResolverto resolve top-level identifiers to managed beans.voidaddELResolver(ELResolver resolver) Adds anELResolverto the front of the resolver chain in the managed EL context.voidaddEvaluationListener(EvaluationListener listener) Registers anEvaluationListenerwith the managed EL context.defineBean(String name, Object bean) Defines or removes a bean accessible by name in EL expressions.Returns theStandardELContextmanaged by this ELManager, creating it on first access if it does not already exist.static ExpressionFactoryReturns theExpressionFactoryused to create and evaluate EL expressions.voidimportClass(String className) Imports a class so it can be referenced by its simple name in EL expressions.voidimportPackage(String packageName) Imports all classes from a package so they can be referenced by their simple names in EL expressions.voidimportStatic(String staticMemberName) Imports a static field or method so it can be referenced by its simple name in EL expressions.voidmapFunction(String prefix, String function, Method method) Maps a static method to an EL function name with the given prefix and local name.setELContext(ELContext context) Replaces the current EL context with a newStandardELContextinitialized from the given context.voidsetVariable(String variable, ValueExpression expression) Registers a variable in the EL context's variable mapper.
-
Constructor Details
-
ELManager
public ELManager()Constructs an ELManager with a lazily initializedStandardELContext.
-
-
Method Details
-
getExpressionFactory
Returns theExpressionFactoryused to create and evaluate EL expressions. The factory is obtained through the standard service discovery mechanism.- Returns:
- the ExpressionFactory instance
-
getELContext
Returns theStandardELContextmanaged by this ELManager, creating it on first access if it does not already exist.- Returns:
- the StandardELContext instance
-
setELContext
Replaces the current EL context with a newStandardELContextinitialized from the given context. The new context copies the ELResolver chain, FunctionMapper, VariableMapper, and other settings from the provided context.- Parameters:
context- the ELContext from which to initialize the new context- Returns:
- the previous StandardELContext, or
nullif none existed
-
addBeanNameResolver
Adds aBeanNameELResolverto the resolver chain that uses the givenBeanNameResolverto resolve top-level identifiers to managed beans.- Parameters:
beanNameResolver- the resolver for bean names
-
addELResolver
Adds anELResolverto the front of the resolver chain in the managed EL context. Resolvers added first have higher priority during property resolution.- Parameters:
resolver- the ELResolver to add
-
mapFunction
Maps a static method to an EL function name with the given prefix and local name. The function can then be invoked in EL expressions asprefix:function(args).- Parameters:
prefix- the namespace prefix for the functionfunction- the local function namemethod- the staticMethodto map
-
setVariable
Registers a variable in the EL context's variable mapper. The variable can then be referenced by name in EL expressions. Passing anullexpression removes the variable.- Parameters:
variable- the variable nameexpression- the ValueExpression associated with the variable, ornullto remove
-
importStatic
Imports a static field or method so it can be referenced by its simple name in EL expressions. The argument must be a fully qualified name in the formclassName.staticMemberName.- Parameters:
staticMemberName- the fully qualified name of the static member to import- Throws:
ELException- if the static member cannot be found or is ambiguous
-
importClass
Imports a class so it can be referenced by its simple name in EL expressions. The argument must be a fully qualified class name.- Parameters:
className- the fully qualified class name to import- Throws:
ELException- if the class name is invalid or conflicts with an existing import
-
importPackage
Imports all classes from a package so they can be referenced by their simple names in EL expressions.- Parameters:
packageName- the package name to import
-
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- Returns:
- the previous bean associated with the name, or
nullif there was none
-
addEvaluationListener
Registers anEvaluationListenerwith the managed EL context. The listener will be notified before and after expression evaluation, and when properties are resolved.- Parameters:
listener- the EvaluationListener to register
-