[jsr-314-open-mirror] [jsr-314-open] CDI constructor integration

Pete Muir pmuir at redhat.com
Sat Jun 26 11:26:32 EDT 2010


On 24 Jun 2010, at 07:46, Roger Kitain wrote:

> Hi Stephan - 
> 
> We have an open issue in Mojarra to support @Inject into JSF Managed Beans.

I believe this is for field injection only.

> 
> Thanks, Roger.
> 
> On 6/24/10 10:42 AM, Stephen Kenna wrote:
>> We have internally been discussing @Inject into @ManagedBeans (should be the same for JSF Managed beans defined in the faces-config.xml). 
>> 
>> Originally we were trying to figure out if JSF managed beans should support constructor injection if they were inside a BDA (in other words, if JSF should defer to CDI for creation). 
>> 
>> We did some testing on Glassfish, and not only did constructor injection not occur, but field injection did not occur either.  (Field injection is working on JBoss) 
>> 
>> My reading of JSR-299 & the EE6 spec differs from this. 
>> 
>> >From JSR299 Section 1.2.1: 
>> In the Java EE 6 environment, all component classes supporting injection, as defined by the Java EE 6 platform specifica- 
>> tion, may inject beans via the dependency injection service. 
>> 
>> Or JSR299 Section 3.8: 
>> An injected field is a non-static, non-final field of a bean class, or of any Java EE component class supporting injection. 
>> 
>> >From the EE6 spec, Section EE.5.20 states: 
>> 
>>     Per the CDI specification, dependency injection is supported on managed 
>> beans. There are currently three ways for a class to become a managed bean: 
>>  1. Being an EJB session bean component. 
>>  2. Being annotated with the @ManagedBean annotation. 
>>  3. Satisfying the conditions in Section 3.1 of the CDI specification. 
>>     Classes that satisfy at least one of these conditions will be eligible for full 
>> dependency injection support, as described in CDI. 
>> 
>> and 
>> 
>>      Clearly, in the absence of any additional annotations, most component classes 
>> listed in Table EE.5-1 will not be managed beans. So as to make injection support 
>> more uniform across all component types, Java EE containers are required to 
>> support field or method injection (but not constructor injection) using 
>> @javax.inject.Inject on all component classes listed in Table EE.5-1 when the 
>> containing archive is a bean archive. 
>>   
>> Our interpretation of the above is that we definitely need to support field injection of @Inject into @ManagedBean beans,

Yes, this is definitely clear :-)

>> and we also need to support constructor injection 

I'm pretty you don't. The @ManagedBean which causes the JSF managed bean container to get involved is *different* to the @ManagedBean which the EE spec indicates should support (javax.faces.bean.ManagedBean vs javax.annotation.Managed - and yes, IMO this is a crazy divergence, and we did argue against it). Using this logic, there is *no way* for a managed bean which lives in the JSF managed bean container to become a managed bean as defined by EE.5.20, and thus support ctor injection. So, JSF managed beans are just required to support field injection.

This is what we check in the CDI TCK.

If you think about it, this makes sense. If you are in a CDI enabled bean archive, then why would you be using JSF managed beans. If you aren't in a CDI enabled bean archive, ctor injection is certainly not required.

HTH





More information about the jsr-314-open-mirror mailing list