5.2.9. Components with multiple roles
Some Seam component classes can fulfill multiple roles in the system. For example, the
User
class is usually a session-scoped component representing the current user, but in user administration screens becomes a conversation-scoped component. The @Role
annotation lets us define an additional named role for a component, with a different scope — it lets us bind the same component class to different context variables. (Any Seam component instance can be bound to multiple context variables, but this lets us do it at the class level to take advantage of automatic instantiation.)
@Name("user") @Entity @Scope(CONVERSATION) @Role(name="currentUser", scope=SESSION) public class User { ... }
The
@Roles
annotation lets us specify additional roles as required.
@Name("user") @Entity @Scope(CONVERSATION) @Roles({ @Role(name="currentUser", scope=SESSION), @Role(name="tempUser", scope=EVENT)}) public class User { ... }