JSF RI 1.2 and Resource Injection
Monday Jan 08, 2007
In the first release of JSF 1.2 up to the latest version, 1.2_03, we've only supported Resource Injection in GlassFish. I'm happy to say that in the next nightly, we'll have improved this support.
How it used to work: The JSF implementation uses a delegation model in order to provide resource injection to managed beans. This was done by providing an implementation of the InjectionProvider interface. Container vendors could then configure this provider via a context initialization parameter in their web.xml, or via a system property. If no provider was configured, then we'd default to a no-op InjectionProvider and no resource injection would be performed.
This was fine for the interim, but not that Jetty and Tomcat are up to speed to the new specifications (or at least getting close to being compliant), having a configuration step to enable resource injection within the JSF-RI seemed a bit too much.
How it now works:
Explicit configuration of InjectionProviders is, of course, still supported, however, if there
is no explicit configuration, then the implementation will query for a META-INF/services entry
com.sun.faces.spi.injectionprovider. This service entry file may contain one or more
entries using the following format:
<InjectionProvider Implementation>:<Injection Delegate>
So an example for GlassFish would be:
com.sun.faces.vendor.GlassFishInjectionProvider:com.sun.enterprise.InjectionManager
InjectionProviders configured this way must extend the
DiscoverableInjectionProvider abstract class. This class
adds a static method isInjectionFeatureAvailable(String delegate) which will be called
by the factory passing in the delegate as configured in the service entry. If this method returns
true, then we put the InjectionProvider into service.
So, for those of you kicking the tires of Tomcat 6.0.2 beta, if you drop in the jsf implementation nightly, resource injection will now work without any configuration steps. I'll be adding an
InjectionProvider for Jetty in the coming days.
So what about folks on Tomcat 5.x using Facelets? Well, we do support a certain degree of
resource injection in that environment as well. If your application includes
the annotation-api.jar (JSR 250), the nightly will support handling methods marked
with the @PostConstruct and @PreDestroy annotations.
Please give the nightlies a shot and
[7] Comments











Today I am wea...ring the implementation hat, not designer hat. But personally I wouldn't make @PreDestroy the responsibility of j2ee when an app developer chooses to remove the bean from scope programmatically. Does the container rollback a user transaction? Oh well.