tags:

views:

81

answers:

3

I need to get access to EL functionality in a Servlet Filter, but... that means I am not within the FacesServlet lifecycle.

Thus, I need to instantiate an ELContext. I do not want to go down the road of instantiating a FacesContext, since that may cause issues when the application does forward to FacesServlet.

Suggestions? Thanks!

+2  A: 

Better use a PhaseListener instead of a Filter.

BalusC
I checked into the ELContext spec... and it's only accessible if provided by either a JSP or JSF Context... so looks like I'd have to instantiated a FacesContext to get this working, which I am already doing but I really just don't like that route... I'll see if a PhaseListener can do what I need.
Lincoln
A PhaseListener is basically kind of JSF Filter which can intercept on the JSF lifecycle phases. In your case you likely need to listen on the `beforePhase` of the `RESTORE_VIEW`, which is the earlymost point to participate with the FacesContext.
BalusC
A: 

I'm not sure it makes sense to do this. Within a JSP context, you would be able to resolve JSP artefacts; within a JSF context, you would be able to resolve JSF artefacts. In a Filter, these artefacts are not going to be available to you.

If you just want to resolve expressions against objects you define, it is possible to create your own context (you may need to know the platform's ExpressionFactory class if you also want to create expressions).

There is probably a better way to achieve whatever it is you are doing, such as BalusC's suggestion of a PhaseListener.

McDowell
I like this possibility, but I think it's too much extra code for what I need to do. I'll just live within Faces :(
Lincoln
A: 

Since I am writing a web-framework, there is no way to use a PhaseListener, this must be done inside the Servlet Filter.

However, I did find the solution in the Seam Solder (WeldX) CDI module - this only works when running on CDI.

http://docs.jboss.org/weld/extensions/reference/latest/en-US/html/elextensions.html

Lincoln