Java Reference
In-Depth Information
Are EJBs and JSF Managed Beans obsolete?
At the end of this chapter, we would like to give our honest opinion about a common ques-
tion posed by developers, that is, how EJB, JSF Managed Beans, and CDI interact and
where the boundary between them lies. Are there redundancies between them? It is indeed
a bit confusing since there are now multiple component models available in Java EE.
JSF Managed Beans have been, for a long time, the actual glue between the application
view and the business methods. Since Release 2.0 of JSF, you can declare JSF Managed
Beans via an annotation, and the scopes are expanded with a view scope and the ability to
create custom scopes. However, there is very little still going on for JSF Managed Beans.
Most of its features can be replaced by CDI Beans that are much more flexible and allow
you to have a better integration with other Java EE components. Even the view scope, in
the newest version of JSF, has been implemented as a CDI custom scope
( javax.faces.view.ViewScoped ), which replaces the old
javax.faces.bean.ViewScoped (notice the name of the package; it's a common
mistake to mix them up).
On the other hand, EJBs, even though they use a less flexible injection mechanism, still
maintain some unique features such as schedulable timers, asynchronous operations, and
pooling that are essential for throttling and assuring that the application provides a good
quality of service. Beginning from Java EE 7, EJBs no longer are the only components that
have a transactional nature. The new @Transactional annotation allows you to use de-
clarative transactions in CDI beans by simply placing it on selected methods.
Despite this, it's likely that EJBs are not disappearing from our code, rather it is likely (and
desirable too) that they will continue to be used for some of their unique features. For the
remaining part though, its functionality will be exposed via CDI instead of EJBs' own an-
notations such as @Stateless and @EJB .
Search WWH ::

Custom Search