Example usage for org.springframework.format FormatterRegistrar registerFormatters

List of usage examples for org.springframework.format FormatterRegistrar registerFormatters

Introduction

In this page you can find the example usage for org.springframework.format FormatterRegistrar registerFormatters.

Prototype

void registerFormatters(FormatterRegistry registry);

Source Link

Document

Register Formatters and Converters with a FormattingConversionService through a FormatterRegistry SPI.

Usage

From source file:cherry.foundation.type.format.DelegateFormatterRegistrar.java

@Override
public void registerFormatters(FormatterRegistry registry) {
    for (Object f : formatters) {
        if (f instanceof FormatterRegistrar) {
            FormatterRegistrar registrar = (FormatterRegistrar) f;
            registrar.registerFormatters(registry);
        }//from  w  w w .j  a  v a 2 s.  com
        if (f instanceof AnnotationFormatterFactory) {
            AnnotationFormatterFactory<?> factory = (AnnotationFormatterFactory<?>) f;
            registry.addFormatterForFieldAnnotation(factory);
        }
    }
}

From source file:com.timeline.vpn.web.common.MyFormattingConversionServiceFactoryBean.java

private void registerFormatters() {
    if (this.formatters != null) {
        for (Object formatter : this.formatters) {
            if (formatter instanceof Formatter<?>) {
                this.conversionService.addFormatter((Formatter<?>) formatter);
            } else if (formatter instanceof AnnotationFormatterFactory<?>) {
                this.conversionService
                        .addFormatterForFieldAnnotation((AnnotationFormatterFactory<?>) formatter);
            } else {
                throw new IllegalArgumentException(
                        "Custom formatters must be implementations of Formatter or AnnotationFormatterFactory");
            }//from  w w  w. ja va  2 s. c  o  m
        }
    }
    if (this.formatterRegistrars != null) {
        for (FormatterRegistrar registrar : this.formatterRegistrars) {
            registrar.registerFormatters(this.conversionService);
        }
    }
    installFormatters(this.conversionService);
}