|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.web.util.ExpressionEvaluationUtils
public abstract class ExpressionEvaluationUtils
Convenience methods for transparent access to JSP 2.0's built-in
ExpressionEvaluator
or the standalone
ExpressionEvaluatorManager
of Jakarta's JSTL implementation.
Automatically detects JSP 2.0 or Jakarta JSTL, preferring the JSP 2.0 mechanism if available. Also detects the JSP 2.0 API being present but the runtime JSP engine not actually supporting JSP 2.0, falling back to the Jakarta JSTL in this case. Throws an exception when encountering actual EL expressions if neither JSP 2.0 nor the Jakarta JSTL is available.
In the case of JSP 2.0, this class will by default use standard
evaluate
calls. If your application server happens to be
inefficient in that respect, consider setting Spring's "cacheJspExpressions"
context-param in web.xml
to "true", which will use
parseExpression
calls with cached Expression objects instead.
The evaluation methods check if the value contains "${" before invoking the EL evaluator, treating the value as "normal" expression (i.e. a literal String value) else.
Note: The evaluation methods do not have a runtime dependency on JSP 2.0 or on Jakarta's JSTL implementation, as long as they are not asked to process actual EL expressions. This allows for using EL-aware tags with Java-based JSP expressions instead, for example.
ExpressionEvaluator.evaluate(java.lang.String, java.lang.Class, javax.servlet.jsp.el.VariableResolver, javax.servlet.jsp.el.FunctionMapper)
,
ExpressionEvaluator.parseExpression(java.lang.String, java.lang.Class, javax.servlet.jsp.el.FunctionMapper)
,
ExpressionEvaluatorManager
Field Summary | |
---|---|
static java.lang.String |
EXPRESSION_CACHE_CONTEXT_PARAM
JSP 2.0 expression cache parameter at the servlet context level (i.e. a context-param in web.xml ): "cacheJspExpressions". |
static java.lang.String |
EXPRESSION_PREFIX
|
static java.lang.String |
EXPRESSION_SUFFIX
|
static java.lang.String |
EXPRESSION_SUPPORT_CONTEXT_PARAM
Expression support parameter at the servlet context level (i.e. a context-param in web.xml ): "springJspExpressionSupport". |
Constructor Summary | |
---|---|
ExpressionEvaluationUtils()
|
Method Summary | |
---|---|
static java.lang.Object |
evaluate(java.lang.String attrName,
java.lang.String attrValue,
java.lang.Class resultClass,
javax.servlet.jsp.PageContext pageContext)
Evaluate the given expression (be it EL or a literal String value) to an Object of a given type, |
static java.lang.Object |
evaluate(java.lang.String attrName,
java.lang.String attrValue,
javax.servlet.jsp.PageContext pageContext)
Evaluate the given expression (be it EL or a literal String value) to an Object. |
static boolean |
evaluateBoolean(java.lang.String attrName,
java.lang.String attrValue,
javax.servlet.jsp.PageContext pageContext)
Evaluate the given expression (be it EL or a literal String value) to a boolean. |
static int |
evaluateInteger(java.lang.String attrName,
java.lang.String attrValue,
javax.servlet.jsp.PageContext pageContext)
Evaluate the given expression (be it EL or a literal String value) to an integer. |
static java.lang.String |
evaluateString(java.lang.String attrName,
java.lang.String attrValue,
javax.servlet.jsp.PageContext pageContext)
Evaluate the given expression (be it EL or a literal String value) to a String. |
static boolean |
isExpressionLanguage(java.lang.String value)
Check if the given expression value is an EL expression. |
static boolean |
isSpringJspExpressionSupportActive(javax.servlet.jsp.PageContext pageContext)
Check whether Spring's JSP expression support is actually active. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String EXPRESSION_SUPPORT_CONTEXT_PARAM
web.xml
): "springJspExpressionSupport".
public static final java.lang.String EXPRESSION_CACHE_CONTEXT_PARAM
web.xml
): "cacheJspExpressions".
public static final java.lang.String EXPRESSION_PREFIX
public static final java.lang.String EXPRESSION_SUFFIX
Constructor Detail |
---|
public ExpressionEvaluationUtils()
Method Detail |
---|
public static boolean isSpringJspExpressionSupportActive(javax.servlet.jsp.PageContext pageContext)
Note that JSP 2.0+ containers come with expression support themselves:
However, it will only be active for web applications declaring Servlet 2.4
or higher in their web.xml
deployment descriptor.
If a web.xml
context-param named "springJspExpressionSupport" is
found, its boolean value will be taken to decide whether this support is active.
If not found, for backwards compatibility with Servlet 2.3 applications,
Spring's expression support will remain active by default.
Recommendations: Explicitly set "springJspExpressionSupport" to "false" in order to prevent double evaluation for Servlet 2.4+ based applications.
pageContext
- current JSP PageContext
true
if active (ExpressionEvaluationUtils will actually evaluate expressions);
false
if not active (ExpressionEvaluationUtils will return given values as-is,
relying on the JSP container pre-evaluating values before passing them to JSP tag attributes)public static boolean isExpressionLanguage(java.lang.String value)
value
- the expression to check
true
if the expression is an EL expression,
false
otherwisepublic static java.lang.Object evaluate(java.lang.String attrName, java.lang.String attrValue, java.lang.Class resultClass, javax.servlet.jsp.PageContext pageContext) throws javax.servlet.jsp.JspException
attrName
- name of the attribute (typically a JSP tag attribute)attrValue
- value of the attributeresultClass
- class that the result should have (String, Integer, Boolean)pageContext
- current JSP PageContext
javax.servlet.jsp.JspException
- in case of parsing errors, also in case of type mismatch
if the passed-in literal value is not an EL expression and not assignable to
the result classpublic static java.lang.Object evaluate(java.lang.String attrName, java.lang.String attrValue, javax.servlet.jsp.PageContext pageContext) throws javax.servlet.jsp.JspException
attrName
- name of the attribute (typically a JSP tag attribute)attrValue
- value of the attributepageContext
- current JSP PageContext
javax.servlet.jsp.JspException
- in case of parsing errorspublic static java.lang.String evaluateString(java.lang.String attrName, java.lang.String attrValue, javax.servlet.jsp.PageContext pageContext) throws javax.servlet.jsp.JspException
attrName
- name of the attribute (typically a JSP tag attribute)attrValue
- value of the attributepageContext
- current JSP PageContext
javax.servlet.jsp.JspException
- in case of parsing errorspublic static int evaluateInteger(java.lang.String attrName, java.lang.String attrValue, javax.servlet.jsp.PageContext pageContext) throws javax.servlet.jsp.JspException
attrName
- name of the attribute (typically a JSP tag attribute)attrValue
- value of the attributepageContext
- current JSP PageContext
javax.servlet.jsp.JspException
- in case of parsing errorspublic static boolean evaluateBoolean(java.lang.String attrName, java.lang.String attrValue, javax.servlet.jsp.PageContext pageContext) throws javax.servlet.jsp.JspException
attrName
- name of the attribute (typically a JSP tag attribute)attrValue
- value of the attributepageContext
- current JSP PageContext
javax.servlet.jsp.JspException
- in case of parsing errors
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |