Skip to main content

JSF, the Unified Expression Language and parse-time EL variables mappings

2 replies [Last post]
Joined: 2008-11-09
Points: 0

I briefly took a look at the Unified Expression Language reference implementation to see how EL variables are "bound" (as cited from UEL 2.1 spec at page 46) by the ExpressionLanguageFactory to the expression object - ValueExpression for example - constructed by this factory ( part of a wider process of the JSP compiler generating the JSP-page's corresponding implementation class and calling the ExpressionlanguageFactory to construct ValueExpression and MethodExpression objects out of strings (this moment is called "expression parse-time") and to pass them to the tag Handlers in the appropriate attributes where this expression was found. But this more general process is not part of this discution).

The spec says
"EL function and variable mapping is performed at parse-time, and the results
are bound to the expression." The term "bound" here simply means to stock these mappings ("EL variable name"-> "Expression object") somehow withing the resulting Expression object (yes, a map of Expression objects inside another Expression object).
OK so when constructing an Expression object, the ExpressionFactory must also save within it these mappings wich are going to be useful when resolving this Expression object.

The implementation does this by simply and directly saving the whole VariableMapper object (subject to another discution ) within the constructed Expression. Here's the signature of the constructor for the ValueExpression implementation:

public final class ValueExpressionImpl extends ValueExpression implements
Externalizable {


public ValueExpressionImpl(String expr, Node node, FunctionMapper fnMapper,
VariableMapper varMapper, Class expectedType) {
this.expr = expr;
this.node = node;
this.fnMapper = fnMapper;
this.varMapper = varMapper;
this.expectedType = expectedType;


So the Expression will have a reference, not a copy as of this moment, of the VariableMapper.

I was just wondering how this works since the VariableMapper is discarded after the rendering phase by the JSP Engine called in at its turn by the ViewHandler's renderView() method(see JSF 1.2 spec at page 2-9 and 7-20) and before the component tree is saved by JSF's ViewHandler.

So the components with ValueExpressions will save state of their ValueExpression objects who now have a reference to a VariableMapper who no longer exists. The value expressions will be evaluated in the "update-model" phase but their internal representations (under the form of a reference to a VariableMapper object, as seen above ) of the EL variable mappings needed in this phase is null.

And lastly should the EL variable mappings of an Expression be represented as the whole VariableMapper object ? Not all the mappings inside it are needed by an Expression, but only those corresponding to the particular variable names used in this Expression. Also the VariableMapper object evolves (its mappings change) when rendering the page by the JSP Engine, but it is referenced by all Expressions who are not "asked" about these changes.


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2004-05-06
Points: 0

Sorry for the late reply. For some reason, I missed your post.

You are right in that the constructor to ValueExpressionImpl only keep the reference of the VariableMapper passed into it. However, the VariableMapper object passed is not the original one from ELContext when the ValueExpression is first created, but a copy of it. All this happens in ExpressionBuilder. Also look at VariableMapperFactory to see that copying is done lazily, viz, only copy the mappings needed for the resolution of the variable, and not the whole map.

Joined: 2008-11-09
Points: 0


thank you in the first place for your response. Never thought i'd get an answer to that anymore, started to think i'm so wrong people won't even bother to show where :)

Hoping you'll be around for next UEL question :)