background image

Using the Standard Converters

<< The requiredMessage Attribute | Converting a Component's Value >>
<< The requiredMessage Attribute | Converting a Component's Value >>

Using the Standard Converters

This message replaces the corresponding message queued on the component and will display
wherever the message or messages tag is placed on the page.
See
"Registering Custom Error Messages" on page 448
and
"Registering Custom Localized Static
Text" on page 449
for information on how to use the message-bundle and resource-bundle
element to register resource bundles that contain error messages.
Using the Standard Converters
The JavaServer Faces implementation provides a set of Converter implementations that you
can use to convert component data. For more information on the conceptual details of the
conversion model, see
"Conversion Model" on page 304
.
The standard Converter implementations, located in the javax.faces.convert package, are
as follows:
BigDecimalConverter
BigIntegerConverter
BooleanConverter
ByteConverter
CharacterConverter
DateTimeConverter
DoubleConverter
FloatConverter
IntegerConverter
LongConverter
NumberConverter
ShortConverter
Each of these converters has a standard error message associated with them. If you have
registered one of these converters onto a component on your page, and the converter is not able
to convert the component's value, the converter's error message will display on the page. For
example, the error message that displays if BigIntegerConverter fails to convert a value is:
{0} must be a number consisting of one or more digits
In this case the {0} substitution parameter will be replaced with the name of the input
component on which the converter is registered. See section 2.4.5 of the JavaServer Faces
specification, version 1.2, for a complete list of error messages.
Two of the standard converters (DateTimeConverter and NumberConverter) have their own
tags, which allow you to configure the format of the component data using the tag attributes.
"Using DateTimeConverter" on page 356
discusses using DateTimeConverter.
"Using
NumberConverter
" on page 357
discusses using NumberConverter. The following section
explains how to convert a component's value including how to register the other standard
converters with a component.
Using the Standard Converters
The Java EE 5 Tutorial · September 2007
354