el-next@uel.java.net

Intercepting EL Expression Evaluation

From: Pete Muir <pmuir_at_redhat.com>
Date: Fri, 9 Apr 2010 15:01:44 +0100

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).

Thoughts?