webtier@glassfish.java.net

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

From: <webtier_at_javadesktop.org>
Date: Mon, 02 Feb 2009 07:07:25 PST

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[b][u] was just wondering how this works[/u][/b] 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.

Thanks
[Message sent by forum member 'vladbalan' (vladbalan)]

http://forums.java.net/jive/thread.jspa?messageID=329632