Java EE 7 CDI bean scopes
Java EE 7 introduced a new set of CDI bean scopes. In the next sections we will summarize each one of the aforementioned scopes while providing links to other articles that will describe them in detail.
|As the name states, a TransactionScoped bean will spawn its life time through the duration of an active transaction. As soon as a bean of this type is referenced by the first time inside a transaction, the CDI container will create an instance of the bean and reuse it across the entire transaction life time, ie. if the bean is referenced again later in the same transaction, the container will provide the same instance to the caller.
|FlowScoped beans are to be used inside JSF Flows. Flows are used to represent units of work and are defined by a contained set of views and beans. A FlowScoped bean will spawn its life time across the duration of the flow where it is referenced by the first time.
|ViewScoped beans will spawn their life time across the duration of a JSF view. Since this kind of beans keep their state during the entire view life time, they become useful to build Ajax interactions between the client and the server in a conversational style.
The following articles cover the Java EE 7 CDI bean scopes in detail:
TransactionScoped beans: Java EE CDI TransactionScoped example
JSF Flows and FlowScoped beans: JSF Flow example
ViewScoped beans: Java EE CDI ViewScoped example