Class Expressions
Provides various utility methods for working with EL expressions.
This utility can be used through injection:
@Inject Expressions expressions;
Alternatively, if you aren't working in a CDI environment, it can be instantiated using the new keyword:
Expressions expressions = new Expressions(context, expressionFactory);
- Author:
- Pete Muir, Dan Allen, Stuart Douglas
-
Constructor Summary
ConstructorsConstructorDescriptionExpressions(jakarta.el.ELContext context, jakarta.el.ExpressionFactory expressionFactory) Create a new instance of theExpressionsclass, providing theELContextandExpressionFactoryto be used. -
Method Summary
Modifier and TypeMethodDescription<T> TevaluateMethodExpression(String expression) Evaluate aMethodExpressionwith no parameters, inferring the return type.<T> TevaluateMethodExpression(String expression, Class<T> expectedReturnType) Evaluate aMethodExpressionwith no parameters.<T> TevaluateMethodExpression(String expression, Class<T> expectedReturnType, Object[] params, Class<?>[] expectedParamTypes) Evaluate aMethodExpression, passing arguments and argument types to the method.<T> TevaluateMethodExpression(String expression, Object... params) Evaluate aMethodExpression, passing arguments to the method.<T> TevaluateValueExpression(String expression) Evaluate aValueExpressioninferring the return type.<T> TevaluateValueExpression(String expression, Class<T> expectedType) Evaluate aValueExpression.jakarta.el.ELContextObtain theELContextthat this instance ofExpressionsis using.jakarta.el.ExpressionFactoryObtain theExpressionFactorythat this instance ofExpressionsis using.toExpression(String name) Convert's a bean name to an EL expression string.
-
Constructor Details
-
Expressions
@Inject public Expressions(@Composite jakarta.el.ELContext context, @Composite jakarta.el.ExpressionFactory expressionFactory) Create a new instance of theExpressionsclass, providing theELContextandExpressionFactoryto be used.- Parameters:
context- theELContextagainst which to operateexpressionFactory- theExpressionFactoryto use- Throws:
IllegalArgumentException- ifcontextis null orexpressionFactoryis null
-
-
Method Details
-
getELContext
public jakarta.el.ELContext getELContext()Obtain theELContextthat this instance ofExpressionsis using.- Returns:
- the
ELContextin use
-
getExpressionFactory
public jakarta.el.ExpressionFactory getExpressionFactory()Obtain theExpressionFactorythat this instance ofExpressionsis using.- Returns:
- the
ExpressionFactoryin use
-
evaluateValueExpression
Evaluate a
ValueExpression.A
ValueExpressionis created by callingExpressionFactory.createValueExpression(ELContext, String, Class)and thenValueExpression.getValue(ELContext)is called to obtain the value. For more details on the semantics of EL, refer to the javadoc for these classes and methods.- Type Parameters:
T- the type of the evaluated expression- Parameters:
expression- the expression to evaluateexpectedType- the expected type of the evaluated expression- Returns:
- the result of evaluating the expression
- Throws:
NullPointerException- if expectedType isnulljakarta.el.ELException- if there are syntactical errors in the provided expression or if an exception was thrown while performing property or variable resolution. The thrown exception will be included as the cause property of this exception, if available.jakarta.el.PropertyNotFoundException- if one of the property resolutions failed because a specified variable or property does not exist or is not readable.ClassCastException- if the result cannot be cast to the expected type- See Also:
-
ExpressionFactory.createValueExpression(ELContext, String, Class)ValueExpression.getValue(ELContext)
-
evaluateValueExpression
Evaluate a
ValueExpressioninferring the return type.A
ValueExpressionis created by callingExpressionFactory.createValueExpression(ELContext, String, Class)and thenValueExpression.getValue(ELContext)is called to obtain the value. For more details on the semantics of EL, refer to the javadoc for these methods.- Type Parameters:
T- the type of the evaluated expression- Parameters:
expression- expression the expression to evaluate- Returns:
- the result of evaluating the expression
- Throws:
jakarta.el.ELException- if there are syntactical errors in the provided expressionjakarta.el.ELException- if an exception was thrown while performing property or variable resolution. The thrown exception will be included as the cause property of this exception, if available.jakarta.el.PropertyNotFoundException- if one of the property resolutions failed because a specified variable or property does not exist or is not readableClassCastException- if the result cannot be cast toT- See Also:
-
ExpressionFactory.createValueExpression(ELContext, String, Class)ValueExpression.getValue(ELContext)
-
evaluateMethodExpression
public <T> T evaluateMethodExpression(String expression, Class<T> expectedReturnType, Object[] params, Class<?>[] expectedParamTypes) Evaluate a
MethodExpression, passing arguments and argument types to the method.A
MethodExpressionis created by callingExpressionFactory.createMethodExpression(ELContext, String, Class, Class[])and thenMethodExpression.invoke(ELContext, Object[])is called to obtain the value. For more details on the semantics of EL, refer to the javadoc for these methods.- Type Parameters:
T- the type of the evaluated expression- Parameters:
expression- expression the expression to evaluateexpectedReturnType- the expected return type of the evaluated expressionparams- arguments to the methodexpectedParamTypes- of the arguments to the method- Returns:
- the result of evaluating the expression
- Throws:
ClassCastException- if the result cannot be cast toexpectedReturnTypejakarta.el.ELException- if there are syntactical errors in the provided expression.NullPointerException- ifexpectedParamTypesisnull.jakarta.el.PropertyNotFoundException- if one of the property resolutions failed because a specified variable or property does not exist or is not readable.jakarta.el.MethodNotFoundException- if no suitable method can be found.jakarta.el.ELException- if a String literal is specified and expectedReturnType of the MethodExpression is void or if the coercion of the String literal to the expectedReturnType yields an error (see Section "1.18 Type Conversion").jakarta.el.ELException- if an exception was thrown while performing property or variable resolution. The thrown exception must be included as the cause property of this exception, if available. If the exception thrown is anInvocationTargetException, extract itscauseand pass it to theELExceptionconstructor.- See Also:
-
MethodExpression.invoke(ELContext, Object[])ExpressionFactory.createMethodExpression(ELContext, String, Class, Class[])
-
evaluateMethodExpression
Evaluate a
MethodExpressionwith no parameters.A
MethodExpressionis created by callingExpressionFactory.createMethodExpression(ELContext, String, Class, Class[])and thenMethodExpression.invoke(ELContext, Object[])is called to obtain the value. For more details on the semantics of EL, refer to the javadoc for these methods.- Type Parameters:
T- the type of the evaluated expression- Parameters:
expression- expression the expression to evaluateexpectedReturnType- the expected return type of the evaluated expression- Returns:
- the result of evaluating the expression
- Throws:
ClassCastException- if the result cannot be cast toexpectedReturnTypejakarta.el.ELException- if there are syntactical errors in the provided expression.NullPointerException- ifexpectedParamTypesisnull.jakarta.el.PropertyNotFoundException- if one of the property resolutions failed because a specified variable or property does not exist or is not readable.jakarta.el.MethodNotFoundException- if no suitable method can be found.jakarta.el.ELException- if a String literal is specified and expectedReturnType of the MethodExpression is void or if the coercion of the String literal to the expectedReturnType yields an error (see Section "1.18 Type Conversion").jakarta.el.ELException- if an exception was thrown while performing property or variable resolution. The thrown exception must be included as the cause property of this exception, if available. If the exception thrown is anInvocationTargetException, extract itscauseand pass it to theELExceptionconstructor.- See Also:
-
MethodExpression.invoke(ELContext, Object[])ExpressionFactory.createMethodExpression(ELContext, String, Class, Class[])
-
evaluateMethodExpression
Evaluate a
MethodExpressionwith no parameters, inferring the return type.A
MethodExpressionis created by callingExpressionFactory.createMethodExpression(ELContext, String, Class, Class[])and thenMethodExpression.invoke(ELContext, Object[])is called to obtain the value. For more details on the semantics of EL, refer to the javadoc for these methods.- Type Parameters:
T- the type of the evaluated expression- Parameters:
expression- expression the expression to evaluate- Returns:
- the result of evaluating the expression
- Throws:
ClassCastException- if the result cannot be cast toTjakarta.el.ELException- if there are syntactical errors in the provided expression.NullPointerException- ifexpectedParamTypesisnull.jakarta.el.PropertyNotFoundException- if one of the property resolutions failed because a specified variable or property does not exist or is not readable.jakarta.el.MethodNotFoundException- if no suitable method can be found.jakarta.el.ELException- if a String literal is specified and expectedReturnType of the MethodExpression is void or if the coercion of the String literal to the expectedReturnType yields an error (see Section "1.18 Type Conversion").jakarta.el.ELException- if an exception was thrown while performing property or variable resolution. The thrown exception must be included as the cause property of this exception, if available. If the exception thrown is anInvocationTargetException, extract itscauseand pass it to theELExceptionconstructor.- See Also:
-
MethodExpression.invoke(ELContext, Object[])ExpressionFactory.createMethodExpression(ELContext, String, Class, Class[])
-
evaluateMethodExpression
Evaluate a
MethodExpression, passing arguments to the method. The types of the arguments are discoverted from the arguments, and the return type is inferred.A
MethodExpressionis created by callingExpressionFactory.createMethodExpression(ELContext, String, Class, Class[])and thenMethodExpression.invoke(ELContext, Object[])is called to obtain the value. For more details on the semantics of EL, refer to the javadoc for these methods.- Type Parameters:
T- the type of the evaluated expression- Parameters:
expression- expression the expression to evaluateparams- arguments to the method- Returns:
- the result of evaluating the expression
- Throws:
ClassCastException- if the result cannot be cast toTjakarta.el.ELException- if there are syntactical errors in the provided expression.NullPointerException- ifexpectedParamTypesisnull.jakarta.el.PropertyNotFoundException- if one of the property resolutions failed because a specified variable or property does not exist or is not readable.jakarta.el.MethodNotFoundException- if no suitable method can be found.jakarta.el.ELException- if a String literal is specified and expectedReturnType of the MethodExpression is void or if the coercion of the String literal to the expectedReturnType yields an error (see Section "1.18 Type Conversion").jakarta.el.ELException- if an exception was thrown while performing property or variable resolution. The thrown exception must be included as the cause property of this exception, if available. If the exception thrown is anInvocationTargetException, extract itscauseand pass it to theELExceptionconstructor.- See Also:
-
MethodExpression.invoke(ELContext, Object[])ExpressionFactory.createMethodExpression(ELContext, String, Class, Class[])
-
toExpression
Convert's a bean name to an EL expression string.- Parameters:
name- the name of the bean to convert- Returns:
- the expression string
-