The Shopping Cart Bean

The shopping cart bean shown below encapsulates the business processing necessary to maintain the user's shopping cart. The bean contains not only the get and set methods for the shopping cart contents but the addMovies method, used to add a collection of movies to the shopping cart, and the deleteMovies method, which allows a collection of movies to be deleted from the shopping cart.

The ShoppingCartBean uses an internal DAO and value object to manage the shopping bean state. A getItemCount method is used to return the count of items in the shopping cart, used by one of the action classes to determine whether or not the cart is empty. (In Chapter 35 we examine how to implement this as an EJB.)

The ShoppingCartBean Class ...

Get J2EE™ and Beyond: Design, Develop, and Deploy World-Class Java™ Software now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.