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

52.  Duke's Tutoring Case Study Example

Design and Architecture of Duke's Tutoring

Administration Interface

Enterprise Beans Used in the Administration Interface

Facelets Files Used in the Administration Interface

Running the Duke's Tutoring Case Study Application

Setting Up GlassFish Server

To Create the JDBC Realm in GlassFish Server

Running Duke's Tutoring

To Build and Deploy Duke's Tutoring in NetBeans IDE

To Build and Deploy Duke's Tutoring Using Ant

Using Duke's Tutoring

53.  Duke's Forest Case Study Example



Main Interface

The main interface allows students and staff to check students in and out, and record when students are outside at the playground.

Java Persistence API Entities Used in the Main Interface

The entities used in the main interface encapsulate data stored and manipulated by Duke’s Tutoring, and are located in the dukestutoring.entity package in the dukes-tutoring-common project.

The Person entity defines attributes common to students, guardians, and administrators tracked by the application. These attributes are the person’s name and contact information, including phone numbers and email address. The phone number and email address attributes have Bean Validation annotations to ensure that the submitted data is well-formed. The email attribute uses a custom validation class, dukestutoring.util.Email. The Person entity has three subclasses, Student, Guardian, and Administrator. For additional data common to all people, the PersonDetails entity is used to store attributes like pictures and the person’s birthday, which aren’t included in the Person entity for performance reasons.

The Student entity stores attributes specific to the students who come to tutoring. This includes information like the student’s grade level and school. The Guardian entity’s attributes are specific to the parents or guardians of a Student. Students and guardians have a many-to-many relationship. That is, a student may have a one or more guardians, and a guardian may have one or more students. The Administrator entity is for staff who manage the tutoring center.

The Address entity represents a mailing address, and is associated with Person entities. Addresses and people have a many-to-one relationship. That is, one person may have many addresses.

The TutoringSession entity represents a particular day at the tutoring center. A particular tutoring session tracks which students attended that day, and which students went to the park. Associated with TutoringSession is the StatusEntry entity, which logs when a student’s status changes. Students’ status changes when they check in to a tutoring session, when they go to the park, and when they check out. The status entry allows the tutoring center staff to track exactly which students attended a tutoring session, when they checked in and out, which students went to the park while they were at the tutoring center, and when they went to and came back from the park.

For information on creating Java Persistence API entities, see Chapter 32, Introduction to the Java Persistence API. For information on validating entity data, seeValidating Persistent Fields and Properties and Chapter 49, Bean Validation: Advanced Topics.

Enterprise Beans Used in the Main Interface

The enterprise beans used in the main interface provide the business logic for Duke’s Tutoring, and are located in the dukestutoring.ejb package in the dukes-tutoring-war project.

ConfigBean is singleton session bean used to create the default students, guardians, and administrator when the application is initially deployed, and to create an automatic EJB timer that creates tutoring session entities every weekday.

RequestBean is a stateless session bean containing the business methods for the main interface. Students or staff can check students in and out and track when they go to and come back from the park. The bean also has business methods for retrieving lists of students. The business methods in RequestBean use strongly-typed Criteria API queries to retrieve data from the database.

For information on creating and using enterprise beans, see Part IV, Enterprise Beans. For information on creating strongly-typed Criteria API queries, see Chapter 35, Using the Criteria API to Create Queries.

Facelets Files Used in the Main Interface

The Duke’s Tutoring application uses Facelets to display the user interface, and makes extensive use of the templating features of Facelets. Facelets is the default display technology for JavaServer Faces, and consists of XHTML files located in the tut-install/examples/case-studies/dukes-tutoring/dukes-tutoring-war/web/ directory.

The following Facelets files are used in the main interface:


Template file for the main interface


Error file employed if something goes wrong


Landing page for the main interface


Page showing who is currently at the park


Page showing who is currently in today’s tutoring session


Page showing the detailed status entry log for today’s session


A composite component for a table displaying all active students


A composite component for a table displaying all students in today’s session


A composite component for a table displaying all students currently at the park


XHTML fragment for the main interface’s navigation bar


XHTML fragment for the main interface’s footer

For information on using Facelets, see Chapter 5, Introduction to Facelets.

Helper Classes Used in the Main Interface

The following helper classes, found in the dukes-tutoring-common project’s dukestutoring.util package, are used in the main interface:


A class that provides a method to strip the unnecessary time data from java.util.Calendar instances


A custom Bean Validation annotation class for validating email addresses in the Person entity


An enumerated type defining the different statuses that a student can have. Possible values are IN, OUT, and PARK. StatusType is used throughout the application, including in the StatusEntry entity, and throughout the main interface. StatusType also defines a toString method that returns a localized translation of the status based on the locale.

The following helper classes, found in the dukes-tutoring-war project’s dukestutoring.web.util package, are used in the JavaServer Faces application:


A parent class to StudentConverter and GuardianConverter that defines a cache to store the entity classes when converting the entities for use in JavaServer Faces user-interface components. The cache helps increase performance. The cache is stored in the JavaServer Faces context.


A JavaServer Faces converter for the Student entity class. This class contains methods to convert Student instances to strings and back again, so they can be used in the user-interface components of the application.


Similar to StudentConverter, this class is a converter for the Guardian entity class.

Properties Files

The strings used in the main interface are encapsulated into resource bundles to allow the display of localized strings in multiple locales. Each of the properties files has locale-specific files appended with locale codes, containing the translated strings for each locale. For example, contains the localized strings for Spanish locales.

The dukestutoring.util package in the dukes-tutoring-common project has the following resource bundle:


Strings for each of the status types defined in the StatusType enumerated type for the default locale. Each supported locale has a property file of the form StatusMessages_locale containing the localized strings. For example, the strings for Spanish-speaking locales are located in

The dukes-tutoring-war project has the following resource bundles:

Strings for the default locale used by the Bean Validation runtime to display validation messages. This file must be named and located in the default package as required by the Bean Validation specification. Each supported locale has a property file of the form ValidationMessages_locale containing the localized strings. For example, the strings for German-speaking locales are located in


Strings for the default locale for the main and administration Facelets interfaces. Each supported locale has a property file of the form Messages_locale containing the localized strings. For example, the strings for simplified Chinese-speaking locales are located in

For information on localizing web applications, see Registering Application Messages.

Deployment Descriptors Used in Duke’s Tutoring

The following deployment descriptors in the dukes-tutoring-war project are used in Duke’s Tutoring:


An empty deployment descriptor file used to enable the CDI runtime


The JavaServer Faces configuration file


The GlassFish-specific configuration file


The web application configuration file

The following deployment descriptor in the dukes-tutoring-common project is used in Duke’s Tutoring:


The Java Persistence API configuration file

No enterprise bean deployment descriptor is used in Duke’s Tutoring. Annotations in the enterprise bean class files are used for the configuration of enterprise beans in this application.