Java Reference
In-Depth Information
Bid
object in detail in a few sections. For now, you should know that a JPA 2 entity holds
all bid data, including the bid amount that's bound by EL to the input text field on the JSF
page. Because the
BidManager
creates and holds a reference to the
Bid
object, it auto-
matically has access to all the bid data entered via the JSF page.
When the
placeBid
method is invoked in response to the button click on the JSF page,
the
BidManager
uses all the data that it has reference to and properly populates the
Bid
object. It then uses the
BidService
stateless session bean to enter the bid into the data-
base. Finally, the user is redirected to a page that confirms the bid.
That's all that we need to say about using CDI with EJB 3 at the presentation tier at the
moment. CDI is used with EJB 3 in a number of other ways, including at the persistence
tier to implement DAOs. Let's take a look at that next.
2.3.2. Using CDI with EJB 3 and JPA 2
In Java EE 7-based systems, the DAO layer is often implemented as EJB 3 beans. This
technique makes a certain amount of sense especially if the DAO is marked with the
transaction-required attribute (we'll discuss this transaction management attribute in detail
safeguard because DAOs often utilize resources that require transactions, such as the data-
base. But for in-house applications where the service and DAO layers are often developed
by the same team, these safeguards aren't always needed. It's possible to develop DAOs
using plain CDI-managed beans and inject them into EJBs at the service tier. To see how
the code looks, let's quickly revisit the
BidService
stateless session bean in the follow-
ing listing.