Java Reference
In-Depth Information
verter. “
Creating and Using a Custom Converter
” on page
123
explains how to implement
a custom converter.
The identifier for the credit card converter class is
ccno
, the value specified in the
@FacesConverter
annotation:
@FacesConverter("ccno")
public class CreditCardConverter implements Converter {
...
Therefore, the
CreditCardConverter
instance can be registered on the
ccno
com-
ponent as shown in the following example:
<h:inputText id="ccno"
size="19"
converter="ccno"
value="#{cashier.creditCardNumber}"
required="true"
requiredMessage="#{bundle.ReqCreditCard}">
...
</h:inputText>
By setting the
converter
attribute of a component's tag to the converter's identifier or
its class name, you cause that component's local value to be automatically converted ac-
cording to the rules specified in the
Converter
implementation.
Instead of referencing the converter from the component tag's
converter
attribute, you
can reference the converter from an
f:converter
tag nested inside the component's
tag. To reference the custom converter using the
f:converter
tag, you do one of the
following:
• Set the
f:converter
tag's
converterId
attribute to the
Converter
im-
plementation's identifier defined in the
@FacesConverter
annotation or in the
application configuration resource file. This method is shown in
bookcash-
ier.xhtml
:
<h:inputText id="ccno"
size="19"
value="#{cashier.creditCardNumber}"
required="true"