Java Reference
In-Depth Information
ent. This is perfectly fine in this case because the BidManager simply acts as the glue
between the JSF page and transactional EJB service tier.
As such, the BidManager is probably fairly self-explanatory even with the various CDI
annotations. The @Named CDI annotation on the BidManager names the compon-
ent. By default, the component is named because the simplified class name is camel-
case. In the case of the BidManager component, the name assigned will be bidMan-
ager . Naming a component is necessary to reference it from JSF EL. As you've seen,
the BidManager.placeBid method is bound to the Place Bid button via an EL bind-
ing expression. The @RequestScoped CDI annotation specifies the scope of the
BidManager . Because the BidManager is request-scoped, the bean will be created
when the JSF page is loaded and destroyed when the user navigates to another page.
A number of other beans are injected into the BidManager component as dependencies.
The first is the BidService stateless session bean you're already familiar with. The
injections for the bidder and item are a bit more interesting. The @LoggedIn and
@SelectedItem annotations are CDI user-defined qualifiers. We'll discuss CDI quali-
fiers in great detail in chapter 12 . For now, what you should understand is that qualifiers
are user-defined metadata used to specify that you want a specific type of bean injected.
For example, in the case of injecting the user into the BidManager , you're specifying
that you want a special kind of user—namely, the currently logged-in user. The code as-
sumes that CDI has a reference to a suitable user instance in some known accessible scope.
Most likely, the User bean corresponding to the logged-in user is in the session scope and
was placed there as part of the login process. Similarly, the BidManager code uses the
@SelectedItem qualifier to specify that it depends on the item that the user has cur-
rently selected. The selected Item bean was likely placed into the request scope when the
user clicked the link to view the item details.
The @Produces , @RequestScoped , and @Named annotations placed on the
getBid method are very interesting as well. As you may have guessed, the @Produces
annotation is a key piece of functionality. The @Produces annotation tells CDI that
the getBid method returns a Bid object that it should manage. The @Named and
@Request-Scoped annotations on the getBid method tell CDI that the returned Bid
object should be named and should be in the request scope. Because the Bid object is
named, it can be referenced in EL just as you did in the JSF page. We'll take a look at the
Search WWH ::




Custom Search