Introduction to ADF Faces Converters and Validators

Validating and Converting Input 6-3 ■ LongConverter ■ NumberConverter ■ ShortConverter Table 6–1 shows the converters provided by ADF Faces. As with validators, the ADF Faces converters are also run on the client side. If no converter is explicitly added, ADF Faces will attempt to create a converter based on the data type. Therefore, if the value is bound to any of the following types, you do not need to explicitly add a converter: ■ java.util.Date ■ java.util.Color ■ java.awt.Color ■ java.lang.Number ■ java.lang.Integer ■ java.lang.Long ■ java.lang.Short ■ java.lang.Byte ■ java.lang.Float ■ java.lang.Double Unlike the converters listed in Table 6–1 , the JavaScript-enabled converters are applied by type and used instead of the standard ones, overriding the class and id attributes. They do not have associated tags that can be nested in the component. Some oracle.jbo.domain datatypes are automatically converted. For some oracle.jbo.domain datatypes that are not handled automatically, you can add a oracle.jbo.domain converter to your component as described in Section 6.3.4, How to Add oracle.jbo.domain Converters.

6.3.1 How to Add a Standard ADF Faces Converter

You can also manually insert a converter into a UI component. Table 6–1 ADF Faces Converters Converter Tag Name Description ColorConverter af:convertColor Converts java.lang.String objects to java.awt.Color objects. You specify a set of color patterns as an attribute of the converter. DateTimeConverter af:convertDateTime Converts java.lang.String objects to java.util.Date objects. You specify the pattern and style of the date as attributes of the converter. NumberConverter af:convertNumber Converts java.lang.String objects to java.lang.Number objects. You specify the pattern and type of the number as attributes of the converter. 6-4 Web User Interface Developers Guide for Oracle Application Development Framework To add ADF Faces converters that have tags: 1. In the Structure window, right-click the component for which you would like to add a converter.

2. In the context menu, choose Insert inside UI component, then ADF Faces to

insert an ADF Faces converter, or JSF Core to insert a JSF converter. 3. Choose a converter tag for example, ConvertDateTime. 4. In the Property Inspector, set values for the attributes, including any messages for conversion errors. For additional help, right-click any of the attributes and choose Help . You can set multiple patterns for some ADF Faces converters. For more information, see Section 6.3.2, How to Set Attributes on a Standard ADF Faces Converter . ADF Faces lets you customize the detail portion of a conversion error message. By setting a value for a MessageDetailxyz attribute, where xyz is the conversion error type for example, MessageDetailconvertDate, ADF Faces displays the custom message instead of a default message, if conversion fails. For more information about creating messages, see Chapter 17, Displaying Tips, Messages, and Help.

6.3.2 How to Set Attributes on a Standard ADF Faces Converter

Patterns specify the format of data accepted for conversion. Multiple patterns allow for more than one format. For example, a user could enter dates using a slash or hyphen - as a separator. Not all converters support multiple patterns, although pattern matching is flexible and multiple patterns may not be needed. Example 6–1 illustrates the use of a multiple pattern for the af:convertColor tag in which 255-255-000 and FFFF00 are both acceptable values. Example 6–1 af:convertColor Multiple Patterns af:inputColor colorData={adfFacesContext.colorPalette.default49} id=sic3 label=Select a color value={demoColor.colorValue4} chooseId=chooseId af:convertColor patterns=rrr-ggg-bbb RRGGBB RRGGBB transparentAllowed=false af:inputColor Example 6–2 illustrates the use of an af:convertDateTime tag in which 692007 and 200796 are both acceptable values. Example 6–2 af:convertDateTime Multiple Patterns af:inputDate id=mdf5 value=20040906 label=attached converter af:convertDateTime pattern=yyyyMd secondaryPattern=dMyyyy af:inputDate Example 6–3 illustrates an af:convertNumber tag with the type attribute set to currency to accepts 78.57 and 078.57 as values for conversion. Example 6–3 af:convertNumber Set to Currency Attribute af:inputText label=type=currency value={validate.currency} af:convertNumber type=currency af:inputText