Java Reference
In-Depth Information
Chapter
15.
Running
the
Advanced
Contexts
and
Dependency Injection Examples
This chapter describes in detail how to build and run several advanced examples that use
CDI. The examples are in the
tut-install
/examples/cdi/
directory.
To build and run the examples, you will do the following:
1.
Use NetBeans IDE or the Ant tool to compile, package, and deploy the example.
2.
Run the example in a web browser.
Each example has a
build.xml
file that refers to files in the
tut-install
/examples/
bp-project/
directory.
See
Chapter 2
,
“
Using the Tutorial Examples
,
” for basic information on installing, building,
and running the examples.
The following topics are addressed here:
Implementation
”
on page
271
on page
273
The
encoder
Example: Using Alternatives
The
encoder
example shows how to use alternatives to choose between two beans at de-
ployment time, as described in
“
Using Alternatives in CDI Applications
” on page
251
. The
example includes an interface and two implementations of it, a managed bean, a Facelets
page, and configuration files.
The
Coder
Interface and Implementations
The
Coder
interface contains just one method,
codeString
, that takes two arguments: a
string, and an integer value that specifies how the letters in the string should be transposed.