| 1 |
<!-- |
| 2 |
|
| 3 |
Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. |
| 4 |
Copyright 2004 The Apache Software Foundation |
| 5 |
|
| 6 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 |
you may not use this file except in compliance with the License. |
| 8 |
You may obtain a copy of the License at |
| 9 |
|
| 10 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
|
| 12 |
Unless required by applicable law or agreed to in writing, software |
| 13 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 14 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 |
See the License for the specific language governing permissions and |
| 16 |
limitations under the License. |
| 17 |
|
| 18 |
--> |
| 19 |
|
| 20 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 21 |
<html> |
| 22 |
<head> |
| 23 |
</head> |
| 24 |
|
| 25 |
<body bgcolor="white"> |
| 26 |
Provides the API for <strong>Jakarta Expression Language 5.0</strong> |
| 27 |
|
| 28 |
<p>Jakarta Expression Language is a simple language originally designed to |
| 29 |
satisfy the specific needs of web application developers. It has evolved |
| 30 |
into its own specification intended for general use inside and outside of the |
| 31 |
web containers.</p> |
| 32 |
|
| 33 |
<p>This package contains the classes and interfaces that describe |
| 34 |
and define the programmatic access to the Jakarta Expression Language engine. |
| 35 |
The API is logically partitioned as follows: |
| 36 |
|
| 37 |
<ul> |
| 38 |
<li><a href="#Context">Jakarta Expression Language Context</a></li> |
| 39 |
<li><a href="#ExpressionObjects">Expression Objects</a></li> |
| 40 |
<li><a href="#ExpressionCreation">Creation of Expressions</a></li> |
| 41 |
<li><a href="#ExpressionEvaluation">Evaluation of Expressions</a></li> |
| 42 |
<li><a href="#EvaluationListener">Evaluation Listeners</a></li> |
| 43 |
<li><a href="#Resolver">Resolution of Model Objects and their Properties</a></li> |
| 44 |
<li><a href="#Functions">Jakarta Expression Language Functions</a></li> |
| 45 |
<li><a href="#Variables">Jakarta Expression Language Variables</a></li> |
| 46 |
<li><a href="#Standalone">Jakarta Expression Language in Stand-alone environment</a></li> |
| 47 |
</ul> |
| 48 |
|
| 49 |
<h3><a name="Context">Jakarta Expression Language Context</a></h3> |
| 50 |
|
| 51 |
<p>An important goal of Jakarta Expression Language is to ensure it can be used in |
| 52 |
a variety of environments. It must therefore provide enough flexibility |
| 53 |
to adapt to the specific requirements of the environment where it is |
| 54 |
being used.</p> |
| 55 |
|
| 56 |
<p>Class {@link jakarta.el.ELContext} is what links |
| 57 |
the Jakarta Expression Language with the specific environment where it is being used. |
| 58 |
It provides the mechanism through which all relevant context for creating or |
| 59 |
evaluating an expression is specified. |
| 60 |
</p> |
| 61 |
|
| 62 |
<p>When Jakarta Expression Language is used in a web container, the creation of <code>ELContext |
| 63 |
</code> objects is controlled through the underlying technology. |
| 64 |
For example, in Jakarta Server Pages, the |
| 65 |
<code>JspContext.getELContext()</code> factory method is used. In an |
| 66 |
stand-alone environment, a default {@link jakarta.el.StandardELContext} is |
| 67 |
provided.</p> |
| 68 |
|
| 69 |
<p>Some technologies provide the ability to add an {@link jakarta.el.ELContextListener} |
| 70 |
so that applications and frameworks can ensure their own context objects |
| 71 |
are attached to any newly created <code>ELContext</code>.</p> |
| 72 |
|
| 73 |
<h3><a name="ExpressionObjects">Expression Objects</a></h3> |
| 74 |
|
| 75 |
<p>At the core of the Expression Language is the notion of an <i>expression</i> |
| 76 |
that gets parsed according to the grammar defined by the Expression Language.</p> |
| 77 |
|
| 78 |
<p>There are two types of expressions defined by Jakarta Expression Language: <i>value expressions</i> |
| 79 |
and <i>method expressions</i>. A {@link jakarta.el.ValueExpression} such as |
| 80 |
<code>"${customer.name}"</code> can be used either |
| 81 |
as an <i>rvalue</i> (return the value associated with property <code>name</code> |
| 82 |
of the model object <code>customer</code>) or as an <i>lvalue</i> |
| 83 |
(set the value of the property <code>name</code> of the model object |
| 84 |
<code>customer</code>).</p> |
| 85 |
|
| 86 |
<p>A {@link jakarta.el.MethodExpression} such as |
| 87 |
<code>"${handler.process}"</code> makes it possible to invoke a method |
| 88 |
(<code>process</code>) on a specific model object (<code>handler</code>).</p> |
| 89 |
|
| 90 |
<p>In version 2.2 and later, either type of Jakarta Expression Language expression can represent a method |
| 91 |
invocation, such as <code>${trader.buy("JAVA")}</code>, where the arguments to |
| 92 |
the method invocation are specified in the expression.</p> |
| 93 |
|
| 94 |
<p>All expression classes extend the base class {@link jakarta.el.Expression}, making them |
| 95 |
serializable and forcing them to implement <code>equals()</code> and |
| 96 |
<code>hashCode()</code>. Moreover, each method on these expression classes |
| 97 |
that actually evaluates an expression receives a parameter |
| 98 |
of class {@link jakarta.el.ELContext}, |
| 99 |
which provides the context required to evaluate the expression.</p> |
| 100 |
|
| 101 |
<h3><a name="ExpressionCreation">Creation of Expressions</a></h3> |
| 102 |
|
| 103 |
<p>An expression is created through the {@link jakarta.el.ExpressionFactory} class. |
| 104 |
The factory provides two creation methods; one for each type of expression |
| 105 |
supported by Jakarta Expression Language.</p> |
| 106 |
|
| 107 |
<p>To create an expression, one must provide an {@link jakarta.el.ELContext}, |
| 108 |
a string representing |
| 109 |
the expression, and the expected type (<code>ValueExpression</code>) or signature |
| 110 |
(<code>MethodExpression</code>). |
| 111 |
|
| 112 |
The <code>ELContext</code> provides the context necessary to parse an expression. |
| 113 |
Specifically, if the expression uses a Jakarta Expression Language function |
| 114 |
(for example <code>${fn:toUpperCase(customer.name)}</code>) or a Jakarta Expression Language |
| 115 |
variable, then {@link jakarta.el.FunctionMapper} and {@link jakarta.el.VariableMapper} |
| 116 |
objects must be available within the <code>ELContext</code> so that Jakarta Expression Language |
| 117 |
functions and Jakarta Expression Language variables are properly mapped. |
| 118 |
|
| 119 |
<h3><a name="ExpressionEvaluation">Evaluation of Expressions</a></h3> |
| 120 |
<p>The creation and the evaluation of an expression are done in two separate |
| 121 |
steps. At the evaluation of an expression, the {@link jakarta.el.ELContext} |
| 122 |
provides the context necessary to support property and method resolution |
| 123 |
for modal objects.</p> |
| 124 |
|
| 125 |
<p>A deferred expression is one that is created but not immediately evaluated. |
| 126 |
In a Jakarta Faces request processing life cycle, Jakarta Expression Language |
| 127 |
expressions are typically created in the tree building phase and evaluated in the |
| 128 |
rendering phrase.</p> |
| 129 |
|
| 130 |
<p>Adding parameters to a <code>ValueExpression</code> further enhances the |
| 131 |
power of deferred expressions. The {@link jakarta.el.LambdaExpression} |
| 132 |
encapsulates such a construct. A <code>LambdaExpression</code> can be |
| 133 |
invoked by supplying the actual parameters at evaluation. It plays |
| 134 |
an important role in the support for collections operators.</p> |
| 135 |
|
| 136 |
<h3><a name="EvaluationListener">Evaluation Listeners</a></h3> |
| 137 |
<p>By registering {@link jakarta.el.EvaluationListener}s in ELContext, a user can |
| 138 |
receive notifications during the Jakarta Expression Language expression evaluations. |
| 139 |
There are three events that trigger the notification: |
| 140 |
<ul> |
| 141 |
<li>Before evaluation</li> |
| 142 |
<li>After evaluation</li> |
| 143 |
<li>When (base, property) is resolved</li> |
| 144 |
</ul></p> |
| 145 |
|
| 146 |
<h3><a name="Resolver">Resolution of Model Objects and their Properties</a></h3> |
| 147 |
|
| 148 |
<p>Through the {@link jakarta.el.ELResolver} base class, Jakarta Expression Language |
| 149 |
features a pluggable mechanism to resolve model object references as well as properties |
| 150 |
and method invocations of these objects.</p> |
| 151 |
|
| 152 |
<p>The Jakarta Expression Language API provides implementations of <code>ELResolver</code> supporting |
| 153 |
property resolution for common data types which include arrays |
| 154 |
({@link jakarta.el.ArrayELResolver}), JavaBeans ({@link jakarta.el.BeanELResolver}), |
| 155 |
<code>List</code>s ({@link jakarta.el.ListELResolver}), |
| 156 |
<code>Map</code>s ({@link jakarta.el.MapELResolver}), and |
| 157 |
<code>ResourceBundle</code>s ({@link jakarta.el.ResourceBundleELResolver}).</p> |
| 158 |
|
| 159 |
<h3><a name="Functions">Jakarta Expression Language Functions</a></h3> |
| 160 |
|
| 161 |
<p>If a Jakarta Expression Language expression uses a function |
| 162 |
(for example <code>${fn:toUpperCase(customer.name)}</code>), then a |
| 163 |
{@link jakarta.el.FunctionMapper} object must also be specified within |
| 164 |
the <code>ELContext</code>. |
| 165 |
|
| 166 |
The <code>FunctionMapper</code> is responsible to map |
| 167 |
<code>${prefix:name()}</code> style functions to |
| 168 |
static methods that can execute the specified functions. |
| 169 |
</p> |
| 170 |
|
| 171 |
<h3><a name="Variables">Jakarta Expression Language Variables</a></h3> |
| 172 |
|
| 173 |
<p>Just like {@link jakarta.el.FunctionMapper} provides |
| 174 |
a flexible mechanism to add functions to Jakarta Expression Language, |
| 175 |
{@link jakarta.el.VariableMapper} provides a flexible mechanism to support the notion of |
| 176 |
<strong>Jakarta Expression Language variables</strong>. |
| 177 |
</p> |
| 178 |
|
| 179 |
<p> |
| 180 |
A Jakarta Expression Language variable does not directly refer to a model object that can then |
| 181 |
be resolved by an <code>ELResolver</code>. Instead, it refers to a Jakarta Expression Language |
| 182 |
expression. The evaluation of that Jakarta Expression Language expression gives the |
| 183 |
Jakarta Expression Language variable its value. |
| 184 |
</p> |
| 185 |
|
| 186 |
<p> |
| 187 |
For example, in the following code snippet |
| 188 |
<blockquote> |
| 189 |
<code><h:inputText value="#{handler.customer.name}"/></code> |
| 190 |
</blockquote> |
| 191 |
|
| 192 |
<code>handler</code> refers to a model object that can be resolved by a Jakarta Expression Language Resolver. |
| 193 |
</p> |
| 194 |
<p> |
| 195 |
However, in this other example: |
| 196 |
<blockquote> |
| 197 |
<pre> |
| 198 |
<c:forEach var="item" items="#{model.list}"> |
| 199 |
<h:inputText value="#{item.name}"/> |
| 200 |
</c:forEach> |
| 201 |
</pre> |
| 202 |
</blockquote> |
| 203 |
|
| 204 |
<code>item</code> is a Jakarta Expression Language variable because it does not refer directly to a model |
| 205 |
object. Instead, it refers to another Jakarta Expression Language expression, namely a |
| 206 |
specific item in the collection referred to by the Jakarta Expression Language expression |
| 207 |
<code>#{model.list}</code>. |
| 208 |
</p> |
| 209 |
|
| 210 |
<p> |
| 211 |
Assuming that there are three elements in <code>${model.list}</code>, this means |
| 212 |
that for each invocation of <code><h:inputText></code>, the following information |
| 213 |
about <code>item</code> must be preserved in the {@link jakarta.el.VariableMapper}: |
| 214 |
<blockquote> |
| 215 |
first invocation: <code>item</code> maps to first element in <code>${model.list}</code><br> |
| 216 |
second invocation: <code>item</code> maps to second element in <code>${model.list}</code><br> |
| 217 |
third invocation: <code>item</code> maps to third element in <code>${model.list}</code><br> |
| 218 |
</blockquote> |
| 219 |
<p> |
| 220 |
<code>VariableMapper</code> provides the mechanisms required to allow the mapping |
| 221 |
of a Jakarta Expression Language variable to the Jakarta Expression Language expression from which it gets its value. |
| 222 |
</p> |
| 223 |
|
| 224 |
<h3><a name="Standalone">Jakarta Expression Language in Stand-alone environment</a></h3> |
| 225 |
<p>Jakarta Expression Language 5.0 includes APIs for using Jakarta Expression Language in a stand-alone environment.</p> |
| 226 |
<p>{@link jakarta.el.ELProcessor} provides simple APIs for the direct |
| 227 |
evaluations of expressions. It also makes it easy to define functions, |
| 228 |
set variables, and define beans locally.</p> |
| 229 |
|
| 230 |
<p>{@link jakarta.el.ELManager} provides lower level APIs for managing the Jakarta Expression Language |
| 231 |
parsing and evaluation environment. It contains a default ELContext {@link jakarta.el.StandardELContext}.</p> |
| 232 |
|
| 233 |
</body> |
| 234 |
</html> |
| 235 |
|