36.12. Seam 2 components
Seam 2 uses Component as a basic building block. But Java EE 6 and CDI defines a Managed Bean as a basic building block. Additionally, while both Seam 2 and CDI support definitions of metadata through annotations, Seam 2 XML configuration is not covered by the CDI specification. These differences are detailed further in the table here.
Table 36.6. Differences in the Component Models
| Seam 2 | CDI | Note |
|---|---|---|
|
Session Bean
|
Session Bean
| |
|
Java Bean
|
Managed Bean
| |
|
Factory method
|
Producer method/field
|
A producer can inject parameters into a method while Seam 2 Factory method cannot.
|
|
Message-driven Bean
|
Message-driven Bean
|
In Seam 2, Message-driven beans may not be bound to a Seam context.
|
|
Entity Bean
|
Entity Bean
|
In Seam 2, Entity beans do not support bijection or context demarcation.
|
|
Resource
|
Reference to a Java EE resource.
| |
|
Component
|
Portable Extension
|
It may provide other kinds of beans.
|
Furthermore, there are some differences in how a Managed bean is defined in comparison to a Seam 2 Component, as detailed in the table here.
Table 36.7. Component Metadata Differences
| Seam 2 component | CDI Managed Bean | Note |
|---|---|---|
|
Must have
@Name.
|
No need to have it.
|
Does not have to have
@Named.
|
|
Available in EL.
|
Only if
@Named is defined.
| |
|
Bijection
|
No bijection.
| |
seam.properties or components.xml
| beans.xml
| |
|
Explicit definition.
|
Implicit recognition.
|
Every Java class in the bean archive that meets certain conditions is implicitly recognized as a managed bean. For CDI no special declaration is required, while Seam 2 needs
@Name or inclusion in XML descriptor.
|
Table 36.8. Component/Managed Bean Metadata
| Seam 2 | CDI |
|---|---|
|
name →
@Name
|
name (optional)
@Named
|
|
scope →
@Scope
|
scope → every scope has special annotation
|
|
roles →
@Roles – single Java class to act as a base for multiple components (comprises name and a scope)
|
Bean type and
@Qualifier - used to distinguish between multiple components sharing the same bean type
|
|
conditional installation →
@Install
|
conditional installation →
@Alternative,@Specializes,@Veto,@Requires
|
36.12.1. Asynchronicity
Seam 2 supports asynchronous method invocation through Dispatcher available components. Several implementations are available, like
TimerService or Quartz Scheduler.
In contrast CDI does not specify asynchronous method invocation and you need to rely on EJB
@Asynchronous observer methods.
36.12.2. Bijection
Bijection is performed dynamically through an Interceptor for every component method invocation. Bijection is bidirectional injection and outjection.
CDI does not supports bijection and does a static injection. It is performed only once per component life cycle and has the following features:
- when creating contextual objects
- injection points: constructor, field, initializer method
- typesafe resolution - the process of matching a bean to an injection point
- bean is assignable to a given injection point if it has a bean type that matches the required type and has all the required qualifiers
- ambiguous and unsatisfied dependency is an error
- no outjection and disinjection
- beans are initialized automatically