Java EE 7 SDK

Samples Main Page

# The JavaServer Faces CDI Sample Application

This sample application demonstrates how to use CDI (Contexts and Dependency Injection) with JavaServer Faces.

## Description

This sample application gives you 10 attempts to guess a number between 1 an 100. After each attempt, the application tells you whether your guess was too high or too low.

The example consists of two qualifiers, an application scopped bean, and a session-scoped bean:

- The `@Random` qualifier injects a random number.
- The `@MaxNumber` qualifier injects the maximum number allowed.
- The application-scoped `Generator` bean generates a random number and the maximum number using producer methods.
- The session-scoped `Game` bean sets up or resets the game, captures and validates the user's guess, and provides feedback with a `FacesMessage`. This bean is the primary entry point of the application.

## Building, Deploying, and Running the Application

Perform the following steps to build, deploy, and run the application:

1. Set up your build environment and configure the application server with which the build system has to work by following the common build instructions.
2. `app_dir` is the sample application base directory: `samples_install_dir/javaee7/cdi/cdi-guess`.
3. Change directory to `app_dir.`
4. Build, deploy, and run the sample application using the `run` outcome.

   `mvn clean verify cargo:run`

5. Use the `clean` outcome to undeploy the sample application and to remove the temporary directories such as `build` and `dist`.

   `mvn clean`

## Troubleshooting

If you have problems when running the application, refer to the troubleshooting document.

Copyright © 1997-2013 Oracle and/or its affiliates. All rights reserved.