[jsr-314-open] getting behind CDI

Cay Horstmann cay at horstmann.com
Wed Dec 23 10:24:35 EST 2009


On 12/19/2009 08:25 AM, Dan Allen wrote:
> If the developer wants to target a native Java EE technology stack, we
> should consider recommending platform managed beans
> (@javax.annotation.ManagedBean) with CDI services. If the developer's
> scope is broader, then we could suggest for them to consider alternative
> bean containers such as Spring. It's even possible to recommend the use
> of @javax.annotation.ManagedBean with @javax.inject.Inject to have a
> bean which is portable to both Java EE and Spring, likely the ideal
> recommendation for setting a common ground.
>
> Hopefully we can all agree that it's time to look past the rudimentary
> JSF managed bean facility. I don't think we do anyone a service by
> showing them the @javax.faces.ManagedBean in examples because it's just
> not going to stand up to the long-term challenges the developer is going
> to face.

I am sorry to be so dense here, but how does 
@javax.annotation.ManagedBean work with JSF 2.0? I just tried out

@javax.annotation.ManagedBean("user")
public class UserBean implements Serializable { ... }

The JSF EL does not pick this up, even in an EE6 container (GlassFish 
v3). This isn't really surprising. The JSR316 spec mandates that the 
name is turned into a JNDI name, but it specifies no interaction with an 
EL.

I tried adding an empty beans.xml to check whether that would trigger a 
lookup by the CDI implementation, but it didn't, and reading the JSR 299 
spec, I don't think it should. Is there some other straightforward way 
of making @javax.annotation.ManagedBean work with the JSF EL?

If not, it would seem to me that we need to use @javax.inject.Named if 
we want to avoid @javax.faces.bean.ManagedBean.

Cheers,

Cay







-- 

Cay S. Horstmann | http://horstmann.com | mailto:cay at horstmann.com




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