The Java EE 5 Tutorial

Using a Custom Converter

As described in the previous section, to apply the data conversion performed by a custom converter to a particular component’s value, you must either reference the custom converter from the component tag’s converter attribute or from a converter tag nested inside the component tag.

If you are using the component tag’s converter attribute, this attribute must reference the Converter implementation’s identifier or the fully-qualified class name of the converter. The application architect provides this identifier when registering the Converter implementation with the application, as explained in Registering a Custom Converter. Creating a Custom Converter explains how a custom converter is implemented.

The identifier for the credit card converter is CreditCardConverter. The CreditCardConverter instance is registered on the ccno component, as shown in this tag from the bookcashier.jsp page:

<h:inputText id="ccno"

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 according 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 a converter tag nested inside the component’s tag. To reference the custom converter using the converter tag, you do one of the following: