-
Book Overview & Buying
-
Table Of Contents
JBoss Weld CDI for Java Platform
By :
When we want to specify qualifiers on an event we intend to fire, there are two ways it can be achieved:
Annotating the Event injection point with qualifiers
Passing qualifiers to the select() method of Event dynamically
As we've seen in previous examples, specifying qualifiers at an injection point is easy.
@Inject @Removed Event<Book> bookRemovedEvent;
Every call to bookRemovedEvent.fire()
will have the event qualifier @Removed
and would match the second observer method we defined earlier in the chapter.
The downside of specifying event qualifiers on the injection point, as just done, is that we are not able to specify event qualifiers dynamically. We can modify our previous Event injection point to the following:
@Inject @Any Event<Book> bookRemovedEvent;
And instead set the qualifier dynamically by using this:
bookEvent
.select( new AnnotationLiteral<Removed>(){} )
.fire(book);The AnnotationLiteral class is a helper class provided by CDI to make it easier...
Change the font size
Change margin width
Change background colour