Top Description Fields Constructors Methods
javax.el

public abstract Class ELContext

extends Object
Class Inheritance
Known Direct Subclasses
javax.el.StandardELContext, javax.faces.view.facelets.FaceletContext
Imports
java.util.Map, .Stack, .HashMap, .List, .ArrayList, .Locale

Context information for expression parsing and evaluation.

To parse or evaluate an Expression, an ELContext must be provided. The ELContext holds:

The collection of context objects is necessary because each ELResolver may need access to a different context object. For example, JSP and Faces resolvers need access to a javax.servlet.jsp.JspContext and a javax.faces.context.FacesContext, respectively.

When used in a web container, the creation of ELContext objects is controlled through the underlying technology. For example, in JSP the JspContext.getELContext() factory method is used. Some technologies provide the ability to add an ELContextListener so that applications and frameworks can ensure their own context objects are attached to any newly created ELContext.

When used in a stand-alone environment, StandardELContext provides a default ELContext, which is managed and modified by ELManager.

Because it stores state during expression evaluation, an ELContext object is not thread-safe. Care should be taken to never share an ELContext instance between two or more threads.

Since
EL 2.1 and EL 3.0
See Also
ELContextListener, ELContextEvent, ELResolver, FunctionMapper, VariableMapper, ImportHandler, LambdaExpression, StandardELContext, javax.servlet.jsp.JspContext

Field Summary

Modifier and TypeField and Description
private ImportHandler
private Stack<Map<String, Object>>
private transient List<EvaluationListener>
private Locale
locale

Holds value of property locale.

private HashMap<Class<?>, Object>
private boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addEvaluationListener(EvaluationListener
The listener to be added.
listener
)

Registers an evaluation listener to the ELContext.

public Object
convertToType(Object
The object to convert.
obj
,
Class<?>
The target type for the conversion.
targetType
)

Converts an object to a specific type.

public void
enterLambdaScope(Map<String, Object>
The Lambda arguments map
args
)

Installs a Lambda argument map, in preparation for the evaluation of a Lambda expression.

public void
exitLambdaScope()

Exits the Lambda expression evaluation.

public Object

Returns:

The context object associated with the given key, or null if no such context was found.
getContext
(Class<T>
The unique identifier that was used to associate the context object with this ELContext.
key
)

Returns the context object associated with the given key.

public abstract ELResolver

Returns:

The resolver to be consulted for variable and property resolution during expression evaluation.
getELResolver
()

Retrieves the ELResolver associated with this context.

public List<EvaluationListener>

Returns:

The list of registered evaluation listeners.
getEvaluationListeners
()

Returns the list of registered evaluation listeners.

public abstract FunctionMapper

Returns:

The function mapper to be consulted for the resolution of EL functions.
getFunctionMapper
()

Retrieves the FunctionMapper associated with this ELContext.

public ImportHandler

Returns:

The import handler to manage imports of classes and packages.
getImportHandler
()

Retrieves the ImportHandler associated with this ELContext.

public Object

Returns:

The object associated with formal parameter. Null if no object has been associated with the parameter.
getLambdaArgument
(String
The formal parameter for the Lambda argument
arg
)

Retrieves the Lambda argument associated with a formal parameter.

public Locale

Returns:

The Locale in which this instance is operating. Used primarily for message localization.
getLocale
()

Get the Locale stored by a previous invocation to setLocale.

public abstract VariableMapper

Returns:

The variable mapper to be consulted for the resolution of EL variables.
getVariableMapper
()

Retrieves the VariableMapper associated with this ELContext.

public boolean

Returns:

true if arg is a LambdaArgument, false otherwise.
isLambdaArgument
(String
A possible Lambda formal parameter name
arg
)

Inquires if the name is a LambdaArgument

public boolean

Returns:

true if the property has been resolved, or false if not.
isPropertyResolved
()

Returns whether an ELResolver has successfully resolved a given (base, property) pair.

public void
notifyAfterEvaluation(String
The EL expression string that has been evaluated
expr
)

Notifies the listeners after an EL expression is evaluated

public void
notifyBeforeEvaluation(String
The EL expression string to be evaluated
expr
)

Notifies the listeners before an EL expression is evaluated

public void
notifyPropertyResolved(Object
The base object
base
,
Object
The property Object
property
)

Notifies the listeners when the (base, property) pair is resolved

public void
putContext(Class<T>
The key used by an @{link ELResolver} to identify this context object.
key
,
Object
The context object to add to the collection.
contextObject
)

Associates a context object with this ELContext.

public void
setLocale(Locale locale)

Sets the Locale for this instance.

public void
setPropertyResolved(boolean
true if the property has been resolved, or false if not.
resolved
)

Called to indicate that a ELResolver has successfully resolved a given (base, property) pair.

public void
setPropertyResolved(Object
The base object
base
,
Object
The property object
property
)

Called to indicate that a ELResolver has successfully resolved a given (base, property) pair and to notify the EvaluationListeners.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

importHandlerback to summary
private ImportHandler importHandler
lambdaArgsback to summary
private Stack<Map<String, Object>> lambdaArgs
listenersback to summary
private transient List<EvaluationListener> listeners
localeback to summary
private Locale locale

Holds value of property locale.

mapback to summary
private HashMap<Class<?>, Object> map
resolvedback to summary
private boolean resolved

Constructor Detail

ELContextback to summary
public ELContext()

Method Detail

addEvaluationListenerback to summary
public void addEvaluationListener(EvaluationListener listener)

Registers an evaluation listener to the ELContext.

Parameters
listener:EvaluationListener

The listener to be added.

Since
EL 3.0
convertToTypeback to summary
public Object convertToType(Object obj, Class<?> targetType)

Converts an object to a specific type. If a custom converter in the ELResolver handles this conversion, it is used. Otherwise the standard coercions is applied.

An ELException is thrown if an error occurs during the conversion.

Parameters
obj:Object

The object to convert.

targetType:Class<?>

The target type for the conversion.

Exceptions
ELException:
thrown if errors occur.
Since
EL 3.0
enterLambdaScopeback to summary
public void enterLambdaScope(Map<String, Object> args)

Installs a Lambda argument map, in preparation for the evaluation of a Lambda expression. The arguments in the map will be in scope during the evaluation of the Lambda expression.

Parameters
args:Map<String, Object>

The Lambda arguments map

Since
EL 3.0
exitLambdaScopeback to summary
public void exitLambdaScope()

Exits the Lambda expression evaluation. The Lambda argument map that was previously installed is removed.

Since
EL 3.0
getContextback to summary
public Object getContext(Class<T> key)

Returns the context object associated with the given key.

The ELContext maintains a collection of context objects relevant to the evaluation of an expression. These context objects are used by ELResolvers. This method is used to retrieve the context with the given key from the collection.

By convention, the object returned will be of the type specified by the key. However, this is not required and the key is used strictly as a unique identifier.

Parameters
key:Class<T>

The unique identifier that was used to associate the context object with this ELContext.

Returns:Object

The context object associated with the given key, or null if no such context was found.

Exceptions
NullPointerException:
if key is null.
getELResolverback to summary
public abstract ELResolver getELResolver()

Retrieves the ELResolver associated with this context.

The ELContext maintains a reference to the ELResolver that will be consulted to resolve variables and properties during an expression evaluation. This method retrieves the reference to the resolver.

Once an ELContext is constructed, the reference to the ELResolver associated with the context cannot be changed.

Returns:ELResolver

The resolver to be consulted for variable and property resolution during expression evaluation.

getEvaluationListenersback to summary
public List<EvaluationListener> getEvaluationListeners()

Returns the list of registered evaluation listeners.

Returns:List<EvaluationListener>

The list of registered evaluation listeners.

Since
EL 3.0
getFunctionMapperback to summary
public abstract FunctionMapper getFunctionMapper()

Retrieves the FunctionMapper associated with this ELContext.

Returns:FunctionMapper

The function mapper to be consulted for the resolution of EL functions.

getImportHandlerback to summary
public ImportHandler getImportHandler()

Retrieves the ImportHandler associated with this ELContext.

Returns:ImportHandler

The import handler to manage imports of classes and packages.

Since
EL 3.0
getLambdaArgumentback to summary
public Object getLambdaArgument(String arg)

Retrieves the Lambda argument associated with a formal parameter. If the Lambda expression is nested within other Lambda expressions, the arguments for the current Lambda expression is first searched, and if not found, the arguments for the immediate nesting Lambda expression then searched, and so on.

Parameters
arg:String

The formal parameter for the Lambda argument

Returns:Object

The object associated with formal parameter. Null if no object has been associated with the parameter.

Since
EL 3.0
getLocaleback to summary
public Locale getLocale()

Get the Locale stored by a previous invocation to setLocale. If this method returns non null, this Locale must be used for all localization needs in the implementation. The Locale must not be cached to allow for applications that change Locale dynamically.

Returns:Locale

The Locale in which this instance is operating. Used primarily for message localization.

getVariableMapperback to summary
public abstract VariableMapper getVariableMapper()

Retrieves the VariableMapper associated with this ELContext.

Returns:VariableMapper

The variable mapper to be consulted for the resolution of EL variables.

isLambdaArgumentback to summary
public boolean isLambdaArgument(String arg)

Inquires if the name is a LambdaArgument

Parameters
arg:String

A possible Lambda formal parameter name

Returns:boolean

true if arg is a LambdaArgument, false otherwise.

isPropertyResolvedback to summary
public boolean isPropertyResolved()

Returns whether an ELResolver has successfully resolved a given (base, property) pair.

The CompositeELResolver checks this property to determine whether it should consider or skip other component resolvers.

Returns:boolean

true if the property has been resolved, or false if not.

See Also
CompositeELResolver
notifyAfterEvaluationback to summary
public void notifyAfterEvaluation(String expr)

Notifies the listeners after an EL expression is evaluated

Parameters
expr:String

The EL expression string that has been evaluated

notifyBeforeEvaluationback to summary
public void notifyBeforeEvaluation(String expr)

Notifies the listeners before an EL expression is evaluated

Parameters
expr:String

The EL expression string to be evaluated

notifyPropertyResolvedback to summary
public void notifyPropertyResolved(Object base, Object property)

Notifies the listeners when the (base, property) pair is resolved

Parameters
base:Object

The base object

property:Object

The property Object

putContextback to summary
public void putContext(Class<T> key, Object contextObject)

Associates a context object with this ELContext.

The ELContext maintains a collection of context objects relevant to the evaluation of an expression. These context objects are used by ELResolvers. This method is used to add a context object to that collection.

By convention, the contextObject will be of the type specified by the key. However, this is not required and the key is used strictly as a unique identifier.

Parameters
key:Class<T>

The key used by an @{link ELResolver} to identify this context object.

contextObject:Object

The context object to add to the collection.

Exceptions
NullPointerException:
if key is null or contextObject is null.
setLocaleback to summary
public void setLocale(Locale locale)

Sets the Locale for this instance. This method may be called by the party creating the instance, such as JavaServer Faces or JSP, to enable the EL implementation to provide localized messages to the user. If no Locale is set, the implementation must use the locale returned by Locale.getDefault( ).

setPropertyResolvedback to summary
public void setPropertyResolved(boolean resolved)

Called to indicate that a ELResolver has successfully resolved a given (base, property) pair. Use setPropertyResolved(Object, Object) if resolved is true and to notify EvaluationListeners.

The CompositeELResolver checks this property to determine whether it should consider or skip other component resolvers.

Parameters
resolved:boolean

true if the property has been resolved, or false if not.

See Also
CompositeELResolver
setPropertyResolvedback to summary
public void setPropertyResolved(Object base, Object property)

Called to indicate that a ELResolver has successfully resolved a given (base, property) pair and to notify the EvaluationListeners.

The CompositeELResolver checks this property to determine whether it should consider or skip other component resolvers.

Parameters
base:Object

The base object

property:Object

The property object

Since
EL 3.0
See Also
CompositeELResolver