I was recently tasked with looking at some mechanisms to control logging in our JSF applications. This included a number of proof of concept ideas to see which Dependency Injection (DI) mechanisms we could use. We are currently using CDI (Weld), and OpenWebbeans in our applications. I had previously used Guice for doing DI in some other applications especially in Java SE which I found it very easy to use.
As I looked around, I found that I could not find a good example of how to use Guice with JSF 2.x. There were a number of articles from over the years for using Guice with JSF 1.2 primarily, but nothing that used some of the great enhancements to JSF 2. I also found very little on how to implement
ELResolver. The exception being
ELResolvercode that you can find in OmniFaces.
ImplementationThe implementation uses a number of techniques to inject our custom
ELResolver. First we will use a
FacesWrapperto wrap the
ApplicationFactory. Our implementation will return a custom
ApplicationWrapperimplementation, that will return a custom
ELResolver. This arrangement may seem complex, but separates the concerns to allow us to refactor them as necessary.
The code for this project can be found here: jsf-guice-logger-integration
There are additional classes that do the logging that can be found in the project. The primary interest here is how to get an
ELResolverimplementation that will resolve our Guice injections. I hope this demonstration of JSF 2.x wrappers can show you how easy it is to implement custom wrappers including a custom