Document Information

Preface

1.  Introduction

2.  Understanding Java Platform, Enterprise Edition

3.  Creating Your First Java EE Application

4.  Creating Your Second Web Application

Creating the firstcup Project

Create the Web Application Project

Creating the Java Persistence API Entity

Create the FirstcupUser Entity Class

Add Properties to the FirstcupUser Entity

Add Constructors to the FirstcupUser Entity

Add a Named Query to the FirstcupUser Entity

Creating the Enterprise Bean

Create the DukesBirthdayBean Enterprise Bean Class

Add a Logger Instance to DukesBirthdayBean.java

Add a Business Method to DukesBirthdayBean that Gets the Average Age Difference of firstcup Users

Add a Business Method for Calculating the Age Difference Between Duke and the User

Creating the Web Client

Creating a Resource Bundle

Create a Resource Bundle

Configuring the Resource Bundle in the Configuration File

Create a Configuration File

Configure the Resource Bundle

Creating the DukesBDay Managed Bean Class

Create the Managed Bean Class

Add an Enterprise Bean Reference

Add Properties to the Bean

Get the Age Difference from the DukesBirthdayBean Enterprise Bean

Creating the Facelets Client

Resource Libraries in firstcup

The inputDate Composite Component

Create the inputDate Composite Component

The Facelets Web Interface

Create the XHTML Files

Set the Welcome File in the web.xml Deployment Descriptor

Modify the XHTML Files

Add the Form to greeting.xhtml

Add the Form to response.html

5.  Next Steps

 

Building, Packaging, Deploying, and Running the firstcup Web Application

In this section, you will build the firstcup web application, deploy it to the server, and run the application.

Build, Package, and Deploy the firstcup Web Application

While performing this task, you'll build and package the DukesBirthdayBean enterprise bean, the FirstcupUser entity, and the firstcup web client into a WAR file, firstcup.war, in the dist directory, then deploy it to the server.

  1. Select the firstcup project in the Projects tab.
  2. Right-click firstcup and select Deploy.

Run the firstcup Application

This section describes how to run the firstcup application.

  1. Launch a web browser.
  2. Type the following URL in the address field of the browser:
    http://localhost:8080/firstcup/
  3. Type your birth date in the Your birthday text field. Make sure you use the date pattern specified on the page: MM/dd/yyyy.
  4. Click Submit.
  5. After the response.xhtml page is displayed, click Back to return to the greeting.xhtml page.
  6. Type a different birthday in the text field and click Submit again to see how the average age of First Cup users changes.

Example 4-1 A Successful Response Page for firstcup

You are 20 years older than Duke!

The average age difference of all First Cup users is 20.0.