Javatpoint Logo
Javatpoint Logo

JSF Standard Converters

The JavaServer Faces provides a set of Converters. You can use that to convert component data. The purpose of conversion is to take the String-based data from the Servlet API and convert it to strongly typed Java objects.

The javax.faces.convert package contains all the standard converters. Converters are implicitly assigned based on the type of the EL expression pointed to by the value of the component. You can also access these converters by converter ID. The following table shows converter classes and their associated converter IDs.

JSF Converters

Class Converter ID
BigDecimalConverter javax.faces.BigDecimal
BigIntegerConverter javax.faces.BigInteger
BooleanConverter javax.faces.Boolean
ByteConverter javax.faces.Byte
CharacterConverter javax.faces.Character
DateTimeConverter javax.faces.Datetime
DoubleConverter javax.faces.Double
EnumConverter javax.faces.Enum
FloatConverter javax.faces.Float
IntegerConverter javax.faces.Integer
LongConverter javax.faces.Long
NumberConverter javax.faces.Number
ShortConverter javax.faces.Short

A standard error message is associated with each of the converters. If you are using any converter 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.

The standard converters DateTimeConverter and NumberConverter both have their own tags, which allow you to configure the format of the component data by using the tag attributes.

JSF Data-Conversion Core Tags

Tag Function
f:converter It is used to add an arbitrary converter to the parent component.
f:convertDateTime It is used to add a DateTimeConverter instance to the parent component.
f:convertNumber It is used to adds a NumberConverter instance to the parent component.

JSF <f:converter> Tag Example

// index.xhtml

// User.java

// response.xhtml

Output:

// index page

JSF Standard converters 1

// response page

JSF Standard converters 2



Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA