Java Reference
In-Depth Information
The managed bean,
CoderBean
, is a
@RequestScoped
bean that declares its input
and output properties. The
transVal
property has three Bean Validation constraints that
enforce limits on the integer value, so that if the user types an invalid value, a default er-
ror message appears on the Facelets page. The bean also injects an instance of the
Coder
interface:
@Named
@RequestScoped
public class CoderBean {
private String inputString;
private String codedString;
@Max(26)
@Min(0)
@NotNull
private int transVal;
@Inject
Coder coder;
...
In addition to simple getter and setter methods for the three properties, the bean defines
the
encodeString
action method called by the Facelets page. This method sets the
codedString
property to the value returned by a call to the
codeString
method of
the
Coder
implementation:
public void encodeString() {
setCodedString(coder.codeString(inputString, transVal));
}
Finally, the bean defines the
reset
method to empty the fields of the Facelets page:
public void reset() {
setInputString("");
setTransVal(0);
}
Running the
encoder
Example
You can use either NetBeans IDE or Ant to build, package, deploy, and run the
encoder
application.