Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
In Seam, you can define components in one of two ways: you can use either annotations or XML. The goal of Seam is to reduce as much XML coding as possible. Therefore, annotations are the preferred mechanism for defining a Seam component. Two common alternatives are the XML-based Seam component descriptor, covered in chapter 5, and Seam’s pluggable container mechanism—the integration that allows Spring beans to serve as Seam components—which is explored in chapter 15 (online). This chapter focuses on the annotation approach. The annotations that dictate how a component is defined are listed in table 4.4. As the chapter develops, I’ll introduce you to each one in detail.
| Annotation | What it does |
|---|---|
| @Name | Declares a class as a Seam component and assigns it a name. When the component name is requested, Seam instantiates a new instance of the class and binds it to the context variable with the same name. |
| @Scope | Specifies the default scope in which the context variable is stored when an instance of the component is instantiated. |
| @Role (@Roles) | Defines alternate name and scope pairings for the component that can be usedto instantiate parallel instances of the same component for different purposes. Multiple @Role declarations are wrapped in a @Roles annotation. |
| @Startup | Instructs Seam to instantiate the component automatically when its assigned context starts (only applies to application-scoped and session-scoped components). |
| @Namespace | Binds a URI to a Java package and used to define custom XML namespaces in the Seam component descriptor. |
| @Install | Used to make installation of a component conditional or to provide a precedence to override another component definition. Conditions include the presence of a class on the classpath, the presence of another component, or the debug mode setting. |
| @AutoCreate | Tells Seam to create a new instance of the component when the component name is first requested, even if the calling code doesn’t request for it to be created. |