jsr341-experts@el-spec.java.net

[jsr341-experts] Intercepting EL expression evaluation

From: Kin-man Chung <kinman.chung_at_oracle.com>
Date: Thu, 15 Sep 2011 16:06:40 -0700

Let's next tackle the issue of intercepting EL evaluations, as required
by CDI.

I still have Pete's mail from last year, reproduced here:

--------------

Any CDI based bean container will likely need to do this - if you take a look Section 6.4 of the CDI spec:

"all @Dependent scoped contextual instances created during evaluation of a Unified EL expression in a JSP or JSF page are destroyed when the evaluation completes."

You can see that we have a need to know when an expression starts to be evaluated (so that we can start collecting the dependent objects) and stops being evaluated (so that we can destroy the dependent objects). We also need a add stuff to the collection as the expression evaluates (for which the ELContext.putContext() method is ideal). So, IOW we have three requirements:

* be notified when an expression evaluation starts
* be notified when an expression evaluation ends
* have the ELContext used for expression evaluation be made available as part of the notification.

As starting point, we could add an interface like:

interface ExpressionEvaluationCallback {

    void beforeEvaluation(ELContext ctx);
    void afterEvaluation(ELContext ctx);

}

However, IMO, a better (more powerful, fits well with the interceptors spec) is reuse the approach there whereby an interceptor method is annotated @AroundInvoke, and takes an argument of type InvocationContext, which allows access to contextual objects such as (in our case) ELContext, and also has a proceed() method which can be used to call the original object (in our case the built in evaluation).

------------


Pete, do you have any updates on this?

I don't see anything wrong with the simple listener type of interface in
Pete's mail, as long as it get the job done. However, let's also explore
the interceptor idea to see what we can do there.

Pete, is it possible to use interceptors without EL knowing about them?
I assume that the actual interceptor classes would not be part of EL,
nor is the configurations that associate them to the EL classes. I also
assume that EL needs to provide a single method for expression
evaluations that can be intercepted. For the stand-alone EL, we do have
ELProcessor.getValue. But for old style EL, the expressions created from
ExpressionFactory.createValueExpression will be evaluated when
ValueExpressionImpl.getValue is called. So we may need to expose the
implementation of ValueExpression, and may have a problem there.

I am probably showing my ignorance about interceptors here. :-) Pete,
can give more details about how this may work? If you can come up with
a tentative concrete proposal, it would be ideal.

Kin-man