Document Information


Part I Introduction

1.  Overview

2.  Using the Tutorial Examples

Part II The Web Tier

3.  Getting Started with Web Applications

4.  JavaServer Faces Technology

5.  Introduction to Facelets

6.  Expression Language

7.  Using JavaServer Faces Technology in Web Pages

8.  Using Converters, Listeners, and Validators

9.  Developing with JavaServer Faces Technology

10.  JavaServer Faces Technology: Advanced Concepts

11.  Using Ajax with JavaServer Faces Technology

12.  Composite Components: Advanced Topics and Example

13.  Creating Custom UI Components and Other Custom Objects

14.  Configuring JavaServer Faces Applications

15.  Java Servlet Technology

16.  Uploading Files with Java Servlet Technology

17.  Internationalizing and Localizing Web Applications

Part III Web Services

18.  Introduction to Web Services

19.  Building Web Services with JAX-WS

20.  Building RESTful Web Services with JAX-RS

21.  JAX-RS: Advanced Topics and Example

Part IV Enterprise Beans

22.  Enterprise Beans

23.  Getting Started with Enterprise Beans

24.  Running the Enterprise Bean Examples

25.  A Message-Driven Bean Example

26.  Using the Embedded Enterprise Bean Container

27.  Using Asynchronous Method Invocation in Session Beans

Part V Contexts and Dependency Injection for the Java EE Platform

28.  Introduction to Contexts and Dependency Injection for the Java EE Platform

29.  Running the Basic Contexts and Dependency Injection Examples

30.  Contexts and Dependency Injection for the Java EE Platform: Advanced Topics

31.  Running the Advanced Contexts and Dependency Injection Examples

Part VI Persistence

32.  Introduction to the Java Persistence API

33.  Running the Persistence Examples

34.  The Java Persistence Query Language

35.  Using the Criteria API to Create Queries

36.  Creating and Using String-Based Criteria Queries

37.  Controlling Concurrent Access to Entity Data with Locking

38.  Using a Second-Level Cache with Java Persistence API Applications

Part VII Security

39.  Introduction to Security in the Java EE Platform

40.  Getting Started Securing Web Applications

41.  Getting Started Securing Enterprise Applications

42.  Java EE Security: Advanced Topics

Part VIII Java EE Supporting Technologies

43.  Introduction to Java EE Supporting Technologies

44.  Transactions

45.  Resources and Resource Adapters

46.  The Resource Adapter Example

47.  Java Message Service Concepts

48.  Java Message Service Examples

49.  Bean Validation: Advanced Topics

50.  Using Java EE Interceptors

Part IX Case Studies

51.  Duke's Bookstore Case Study Example

Design and Architecture of Duke's Bookstore

Running the Duke's Bookstore Case Study Application

To Build and Deploy Duke's Bookstore Using NetBeans IDE

To Build and Deploy Duke's Bookstore Using Ant

To Run Duke's Bookstore

52.  Duke's Tutoring Case Study Example

53.  Duke's Forest Case Study Example



The Duke’s Bookstore Interface

This section provides additional detail regarding the components of the Duke’s Bookstore example and how they interact.

The Book Java Persistence API Entity

The Book entity, located in the dukesbookstore.entity package, encapsulates the book data stored by Duke’s Bookstore.

The Book entity defines attributes used in the example:

  • A book ID

  • The author’s first name

  • The author’s surname

  • The title

  • The price

  • Whether the book is on sale

  • The publication year

  • A description of the book

  • The number of copies in the inventory

The Book entity also defines a simple named query, findBooks.

Enterprise Beans Used in Duke’s Bookstore

Two enterprise beans located in the dukesbookstore.ejb package provide the business logic for Duke’s Bookstore.

BookRequestBean is a stateless session bean that contains the business methods for the application. The methods create, retrieve, and purchase books, and update the inventory for a book. To retrieve the books, the getBooks method calls the findBooks named query defined in the Book entity.

ConfigBean is a singleton session bean used to create the books in the catalog when the application is initially deployed. It calls the createBook method defined in BookRequestBean.

Facelets Pages and Managed Beans Used in Duke’s Bookstore

The Duke’s Bookstore application uses Facelets and its templating features to display the user interface. The Facelets pages interact with a set of CDI managed beans that provide the underlying properties and methods for the user interface. The front page also interacts with the custom components used by the application.

The application uses the following Facelets pages, which are located in the tut-install/examples/case-studies/dukes-bookstore/web/ directory:


The template file, which specifies a header used on every page as well as the style sheet used by all the pages. The template also retrieves the language set in the web browser.

Uses the LocaleBean managed bean.


Landing page, which lays out the custom map and area components using managed beans configured in the faces-config.xml file, and allows the user to select a book and advance to the bookstore.xhtml page.


Page that allows the user to obtain details on the selected book or the featured book, to add either book to the shopping cart, and to advance to the bookcatalog.xhtml page.

Uses the BookstoreBean managed bean.


Page that shows details on a book selected from bookstore.xhtml or other pages and allows the user to add the book to the cart and/or advance to the bookcatalog.xhtml.

Uses the BookDetailsBean managed bean.


Page that displays the books in the catalog and allows the user to add books to the shopping cart, view the details for any book, view the shopping cart, empty the shopping cart, or purchase the books in the shopping cart.

Uses the CatalogBean and ShoppingCart managed beans.


Page that displays the contents of the shopping cart and allows the user to remove items, view the details for an item, empty the shopping cart, purchase the books in the shopping cart, or return to the catalog.

Uses the ShowCartBean and ShoppingCart managed beans.


Page that allows the user to purchase books, specify a shipping option, subscribe to newsletters, or join the Duke Fan Club with a purchase over a certain amount.

Uses the CashierBean and ShoppingCart managed beans.


Page that confirms the user’s purchase and allows the user to return to the catalog page to continue shopping.

Uses the CashierBean managed bean.

In addition to the managed beans used by the Facelets template and pages, the application uses the following managed beans:


Contains utility methods called by other managed beans.


Contains methods called by ShoppingCart, CatalogBean, and ShowCartBean.

Custom Components and Other Custom Objects Used in Duke’s Bookstore

The map and area custom components for Duke’s Bookstore, along with associated renderer, listener, and model classes, are defined in the following packages in the tut-install/examples/case-studies/dukes-bookstore/src/java/dukesbookstore/ directory:


Contains the MapComponent and AreaComponent classes. See Creating Custom Component Classes.


Contains the AreaSelectedEvent class, along with other listener classes. See Handling Events for Custom Components.


Contains the ImageArea class. See Configuring Model Data.


Contains the MapRenderer and AreaRenderer classes. See Delegating Rendering to a Renderer.

The tut-install/examples/case-studies/dukes-bookstore/src/java/dukesbookstore/ directory also contains a custom converter and other custom listeners not specifically tied to the custom components:


Contains the CreditCardConverter class. See Creating and Using a Custom Converter.


Contains the LinkBookChangeListener, MapBookChangeListener, and NameChanged classes. See Implementing an Event Listener.

Properties Files Used in Duke’s Bookstore

The strings used in the Duke’s Bookstore application are encapsulated into resource bundles to allow the display of localized strings in multiple locales. The properties files, located in the tut-install/examples/case-studies/dukes-bookstore/src/java/dukesbookstore/web/messages/ directory, consist of a default file containing English strings and three additional files for other locales. The files are as follows:

Default file, containing English strings

File containing German strings

File containing Spanish strings

File containing French strings

The language setting in the user’s web browser determines which locale is used. The html tag in bookstoreTemplate.xhtml retrieves the language setting from the language property of LocaleBean:

<html lang="#{localeBean.language}"

For more information about resource bundles, see Chapter 17, Internationalizing and Localizing Web Applications.

The resource bundle is configured as follows in the faces-config.xml file:


This configuration means that in the Facelets pages, messages are retrieved using the prefix bundle with the key found in the file, as in the following example from the index.xhtml page:

<h:outputText style="font-weight:bold" 
              value="#{bundle.ChooseBook}" />

In, the key string is defined as follows:

ChooseBook=Choose a Book from our Catalog

Deployment Descriptors Used in Duke’s Bookstore

The following deployment descriptors are used in Duke’s Bookstore:


The Java Persistence API configuration file


An empty deployment descriptor file used to enable the CDI runtime


The tag library descriptor file for the custom components


The JavaServer Faces configuration file, which configures the managed beans for the map component as well as the resource bundles for the application


The GlassFish-specific configuration file


The web application configuration file