concept @name in category seam

appears as: @Name, @Name
Seam in Action

This is an excerpt from Manning's book Seam in Action.

When the temptation arises to define JSF managed beans in XML, Seam just says “No!,” a tenet that is captured in figure 1.4. Seam reduces the declaration of a component to a single annotation, @Name, placed above the class definition. Seam components can take the place of JSF managed beans.

In the golf tips application, the TipAction class, shown in listing 1.2, is declared as a Seam component using the @Name annotation and is thus capable of having its methods bound to UI controls. It handles the add and delete operations in the golf tips interface.

Listing 1.2. The action listener for the JSF view

Like the GolfTip entity class, the @Name annotation marks the TipAction class as a Seam component, this time scoped to the event context (the default scope for JavaBean components). What sets this component apart from the GolfTip entity class is that it is capable of having other components “wired” into it because the @In annotation is placed above certain fields of the class , a mechanism known as bijection. In this example, the two dependent components are the JPA EntityManager and Seam’s built-in JSF messages manager. This component also prepares a collection of GolfTip objects for use in the JSF view ; captures the GolfTip that the user selects from that collection, making it available to both the method handling the event and the subsequent view ; and interpolates the active GolfTip in the JSF status messages .

The second role of entity classes in a Seam application is to serve as form “backing” beans (akin to a Struts ActionForm) to capture input from the user, thus replacing the need for a shallow “backing” bean class. An entity class becomes a candidate for use in a JSF view if it has a @Name annotation on its class definition, a condition that is satisfied by the GolfTip class in listing 1.1. You then bind the form inputs directly to properties on the entity class and JSF handles the necessary conversions and validations.

Listing 1.1. The JPA entity class that represents a golf tip
@Entity @Name("tip") public class GolfTip implements Serializable { @Id @GeneratedValue protected Long id; protected String author; protected String category; protected String content; // getters/setters for author, category and content not shown }

The keywords prefixed with the @ symbol are Java 5 annotations. The @Name annotation , shown in bold, is a Seam annotation that registers the GolfTip class as a Seam component named tip. Whenever the context variable tip is requested from the Seam container, Seam creates a new instance of the GolfTip class, binds the instance to the tip context variable in the conversation context (the default scope for entity classes), and returns the instance to the requester.