16.3.3 Conversion model

JSF components can be associated with server-side object data, represented by a Java Beans component. When this occurs, the application has two views of the component's data:

The model view, in which data is represented as data types, such as int or long.

The presentation view, in which data is represented in a manner that can be read or updated by the user. For example, a java.util.Date might be represented as a text string in the format mm/dd/yyyy or a set of tree text strings.

The JSF implementation automatically converts component data between these two views when the bean property associated with the component is of one of the types presented in Table 16-1. For example, if a UIInput component is associated with bean property of type int, the JSF implementation will automatically convert the components data from String to int.

You might want to convert a component's data to a type other than a standard type. To allow this, JSF technology provides a way for you to register a Converter implementation on UIOutput components and components whose classes subclass UIOutput.

You can either use the standard converters that come with JSF implementation or create your own custom converter. In order to create and use a custom converter, three things must happen:

The Converter interface must be implemented.

The newly created Converter must be registered with the application, in the application configuration resource file. This is done in the Converter tag.

The Converter tag must be referenced from the tag of the component whose data must be converted.

The following sections explain how to make each of these three things happen.


Redbooks
ibm.com/redbooks