Class: ConverterFactory

Oracle® JavaScript Extension Toolkit (JET)
5.0.0

E90577-01

QuickNav

Fields

ConverterFactory

Version:
  • 5.0.0
Since:
  • 0.6
Module:
  • ojvalidation-base

Constructor

(abstract) new ConverterFactory()

Contract for a ConverterFactory that provides a factory method to create a converter instance for the requested type. JET provides three factory implementations for number and datetime and color types that implement this contract. Customers can register custom converter factories for the supported types or create and register factories for new types altogether.
See:

Fields

(static) CONVERTER_TYPE_COLOR :string

Default type for a factory used to create color converters. This type is passed to the Validation.converterFactory method to retrieve the color converter factory of type oj.ColorConverterFactory.
Example

Create a JET color converter with options

this._convFactory = oj.Validation.converterFactory(oj.ConverterFactory.CONVERTER_TYPE_COLOR);
this._convHex  =  this._convFactory.createConverter({"format": "hex"})

(static) CONVERTER_TYPE_DATETIME :string

Default type for a factory used to create datetime converters. This type is passed to the Validation.converterFactory method to retrieve the datetime converter factory of type oj.DateTimeConverterFactory.
Example

Create a JET dateTime converter with options

var dateTimeCvtr = oj.Validation.converterFactory(oj.ConverterFactory.CONVERTER_TYPE_DATETIME);
var dateOptions = {day: 'numeric', month: 'numeric'};
var dayMonthConverter = dateTimeCvtr.createConverter(dateOptions);

(static) CONVERTER_TYPE_NUMBER :string

Default type for a factory used to create number converters. This type is passed to the Validation.converterFactory method to retrieve the number converter factory of type oj.NumberConverterFactory.
Example

Create a JET number converter with options

var convFactory = oj.Validation.converterFactory(oj.ConverterFactory.CONVERTER_TYPE_NUMBER);
var converter  =  convFactory.createConverter({
 style: 'currency', 
 currency: 'USD', 
 currencyDisplay: 'symbol', 
 pattern: '¤ ##,##0.00'});

Methods

createConverter(options) → {Object}

Creates an immutable converter instance of the type the factory implements.
Parameters:
Name Type Description
options Object | null an object literal containing properties required by the converter for its initialization. The properties provided in the options is implementation specific.
Throws:
if an unrecognized type was provided
Type
TypeError
Returns:
a converter instance.
Type
Object
Examples

Create a JET dateTime converter with options

var dateTimeCvtr = oj.Validation.converterFactory(oj.ConverterFactory.CONVERTER_TYPE_DATETIME);
var dateOptions = {day: 'numeric', month: 'numeric'};
var dayMonthConverter = dateTimeCvtr.createConverter(dateOptions);

Create your own ConverterFactory and Converter, register the Converter on your ConverterFactory, and use it when displaying information on the page to the user.

----- Javascript -----
RelativeDateTimeConverterFactory = (function () {
 function _createRelativeDateTimeConverter(options)
 {
   // this is a custom converter (code not shown here) that formats the datetime into "Today" or 
   // "Tomorrow", or "This Week"/"Next Week", etc.
   return new RelativeDateTimeConverter(options);
 }
 return {
   'createConverter': function (options) {
     return _createRelativeDateTimeConverter(options);
   }
 };
 }());
oj.Validation.converterFactory("relativeDate", RelativeDateTimeConverterFactory);
 // Use our custom relativeDate converter.
 // In this demo, we want to see in the Schedule For column the words 
 // Today or Tomorrow so we set the relativeField option's value
 // to 'day'. If we want to see This Week, we'd set it to 'week', etc.
 var rdConverter =  oj.Validation.converterFactory("relativeDate")
 .createConverter({relativeField: 'day', year: "numeric", month: "numeric", day: "numeric"});
 ...
 // Our custom converter's format function returns an object with 'value' and 'title'.
 // We put the 'value' in innerHTML so the user can read it. E.g., Today or Tomorrow.
 // And we put the actual date in the title. The user can read it when they hover over
 // the word Today or Tomorrow.
 content = rdConverter.format(context.row.ScheduleFor);
 span.setAttribute('title', content.title);
 span.innerHTML = content.value;
...