Java Reference
In-Depth Information
ant undeploy
ant
ant deploy
5. In the web browser, retype the URL to show the String Encoder page for the
redeployed project:
http://localhost:8080/encoder
6. Type a string and the number of letters to shift by, then click Encode.
This time, the Result line displays your arguments. For example, if you type
Java
and
4
, the result is:
Result: input string is Java, shift value is 4
The
producermethods
Example:
Using
a
Producer
Method
To
Choose a Bean Implementation
The
producermethods
example shows how to use a producer method to choose
between two beans at runtime, as described in “
Using Producer Methods, Producer Fields,
and Disposer Methods in CDI Applications
” on page
254
. It is very similar to the
en-
The example includes the same interface and two implementations of it, a managed bean,
a Facelets page, and configuration files. It also contains a qualifier type. When you run it,
you do not need to edit the
beans.xml
file and redeploy the application to change its
behavior.
Components of the
producermethods
Example
The components of
producermethods
are very much like those for
encoder
, with
some significant differences.
Neither implementation of the
Coder
bean is annotated
@Alternative
, and the
beans.xml
file does not contain an
alternatives
element.
The Facelets page and the managed bean,
CoderBean
, have an additional property,
coderType
, that allows the user to specify at runtime which implementation to use. In
addition, the managed bean has a producer method that selects the implementation using
a qualifier type,
@Chosen
.
The bean declares two constants that specify whether the coder type is the test implement-
ation or the implementation that actually shifts letters: