Java Reference
In-Depth Information
You might have noticed that we placed two annotations on the bean:
@Named
and
@ViewScoped
. If you would like to define multiple beans with a specific set of CDI an-
notations, it would be a good idea to create your own custom annotation that already con-
tains the desired ones. This kind of construction is called a stereotype. It is possible to in-
corporate the following elements:
• A default scope
• Optionally, interceptor bindings
• Optionally, a
@Named
annotation
• Optionally, an
@Alternative
annotation
To create a stereotype, you need to add the wanted annotations along with the
@Stereo-
type
annotation:
@ViewScoped
@Named
@Stereotype
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface NamedView {
}
Now you can define the
BookinRecord
bean as follows:
@NamedView
public class BookingRecord implements Serializable {
//Some code here
}
The
@Model
stereotype is available in CDI by default. It defines a request scoped named
bean, and you can use it on your beans right out of the box.
Running the application
With all the libraries in place, you can now test run your new rich application. As you can
see, every 30 seconds a ticket is sold out and buttons are turned, in real time, into
Not
available
: