background image

The CustomerBean Component

<< Client Components | Request Processing >>
<< Client Components | Request Processing >>

The CustomerBean Component

</managed-bean>
<managed-bean>
<managed-bean-name>customerBean</managed-bean-name>
<managed-bean-class>
com.sun.tutorial.javaee.dukesbank.web.CustomerBean
</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
As shown by the preceding configurations, an AccountHistoryBean instance is saved into
request scope under the name accountHistoryBean, and a CustomerBean instance is saved into
session scope under the name customerBean. EL expressions use these names to reference the
beans from a page. The managed bean configurations can also initialize bean properties with
values. As shown in the preceding configuration, the accountId property of
AccountHistoryBean
is set to the expression #{param.accountId} when an instance of
AccountHistoryBean
is created. This expression references the accountId variable in the
request parameter map. This is so that other pages in the application can pass the account ID to
AccountHistoryBean
and therefore make it available to the accountHist.jsp page.
Responsibility for managing the enterprise beans used by the web client rests with
CustomerBean
. It creates account and transaction controller enterprise beans and provides
methods for retrieving the beans.
When instantiated, the CustomerBean component uses @EJB annotations to inject references to
the enterprise beans. Because these enterprise beans apply to a particular customer or session,
CustomerBean
is stored in session.
public class CustomerBean {
@EJB
private AccountController accountController;
@EJB
private TxController txController;
...
}
CustomerBean
also does the following:
Maintains the customer ID
Retrieves the list of accounts from the database
Gets detailed information about a particular account
Invalidates a session to allow a customer to log out.
Because CustomerBean is in session, it is a convenient place to keep account information so that
the backing beans and their associated pages can pass this information between themselves.
Web Client
The Java EE 5 Tutorial · September 2007
1070