Java Reference
In-Depth Information
The interoperability between the two technologies makes it much easier to call singleton,
stateless, and stateful session beans. CDI's DI will support the injection of EJBs into CDI
beans. This eliminates the need to write code that will retrieve beans from JNDI. Just
add the @Inject annotation and CDI will take care of the rest. Thus, using EJBs has
never been easier—you can treat an EJB bean just like any other POJO. Furthermore,
if a CDI bean takes on additional functionality, you can simply add a @Stateless ,
@Singleton , and @Stateful annotation and make your bean an EJB.
CDI isn't a replacement technology for EJBs but a powerful enhancement. CDI not only
empowers EJB, it also greatly augments JSF.
12.1.3. Relationship between CDI and JSF 2
We've already touched on the key aspects of the relationship between CDI and JSF 2. CDI
provides a robust replacement for JSF-backing beans. The enhanced beans provided by
CDI are much more feature-rich as compared to JSF-backing beans. CDI beans are much
more flexible—you don't need to define your beans in faces-config.xml. With CDI, prac-
tically any Java object can be a bean, and you have several different methods of instantiat-
ing a bean. CDI beans can be used as a drop-in replacement for JSF-managed beans.
Although we've already covered the relationship between CDI and EJB, CDI has a big im-
pact on the use of EJBs from JSF. With CDI, JSF can directly invoke methods on EJBs.
You no longer have to write glue code to connect JSF with EJBs. Thus, from a JSF page
you can directly invoke a method on a singleton, stateless, or stateful session bean. EJBs
can be directly resolved from Expression Language (EL) expressions.
We emphasize the strong interoperability between CDI and JSF, but CDI isn't tied to JSF.
JSF benefits from the services provided by CDI, but CDI itself is agnostic to the web frame-
work. Going forward, CDI support will undoubtedly be supported by other web frame-
works. Already there's a plug-in enabling CDI and Struts 2 to interoperate. Because CDI
is now a core part of Java EE 6 and 7 and is also mandated by the web profile, support for
CDI will only continue to grow. Now that you have a conceptual understanding of CDI,
let's take a quick look at the basics of CDI beans.
Search WWH ::




Custom Search