Java Code Examples for org.springframework.format.FormatterRegistry#addFormatter()

The following examples show how to use org.springframework.format.FormatterRegistry#addFormatter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultFormattingConversionService.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Add formatters appropriate for most environments: including number formatters,
 * JSR-354 Money & Currency formatters, JSR-310 Date-Time and/or Joda-Time formatters,
 * depending on the presence of the corresponding API on the classpath.
 * @param formatterRegistry the service to register default formatters with
 */
public static void addDefaultFormatters(FormatterRegistry formatterRegistry) {
	// Default handling of number values
	formatterRegistry.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory());

	// Default handling of monetary values
	if (jsr354Present) {
		formatterRegistry.addFormatter(new CurrencyUnitFormatter());
		formatterRegistry.addFormatter(new MonetaryAmountFormatter());
		formatterRegistry.addFormatterForFieldAnnotation(new Jsr354NumberFormatAnnotationFormatterFactory());
	}

	// Default handling of date-time values
	if (jsr310Present) {
		// just handling JSR-310 specific date and time types
		new DateTimeFormatterRegistrar().registerFormatters(formatterRegistry);
	}
	if (jodaTimePresent) {
		// handles Joda-specific types as well as Date, Calendar, Long
		new JodaTimeFormatterRegistrar().registerFormatters(formatterRegistry);
	}
	else {
		// regular DateFormat-based Date, Calendar, Long converters
		new DateFormatterRegistrar().registerFormatters(formatterRegistry);
	}
}
 
Example 2
Source File: DefaultFormattingConversionService.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Add formatters appropriate for most environments: including number formatters,
 * JSR-354 Money & Currency formatters, JSR-310 Date-Time and/or Joda-Time formatters,
 * depending on the presence of the corresponding API on the classpath.
 * @param formatterRegistry the service to register default formatters with
 */
public static void addDefaultFormatters(FormatterRegistry formatterRegistry) {
	// Default handling of number values
	formatterRegistry.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory());

	// Default handling of monetary values
	if (jsr354Present) {
		formatterRegistry.addFormatter(new CurrencyUnitFormatter());
		formatterRegistry.addFormatter(new MonetaryAmountFormatter());
		formatterRegistry.addFormatterForFieldAnnotation(new Jsr354NumberFormatAnnotationFormatterFactory());
	}

	// Default handling of date-time values

	// just handling JSR-310 specific date and time types
	new DateTimeFormatterRegistrar().registerFormatters(formatterRegistry);

	if (jodaTimePresent) {
		// handles Joda-specific types as well as Date, Calendar, Long
		new JodaTimeFormatterRegistrar().registerFormatters(formatterRegistry);
	}
	else {
		// regular DateFormat-based Date, Calendar, Long converters
		new DateFormatterRegistrar().registerFormatters(formatterRegistry);
	}
}
 
Example 3
Source File: DefaultFormattingConversionService.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Add formatters appropriate for most environments: including number formatters,
 * JSR-354 Money & Currency formatters, JSR-310 Date-Time and/or Joda-Time formatters,
 * depending on the presence of the corresponding API on the classpath.
 * @param formatterRegistry the service to register default formatters with
 */
public static void addDefaultFormatters(FormatterRegistry formatterRegistry) {
	// Default handling of number values
	formatterRegistry.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory());

	// Default handling of monetary values
	if (jsr354Present) {
		formatterRegistry.addFormatter(new CurrencyUnitFormatter());
		formatterRegistry.addFormatter(new MonetaryAmountFormatter());
		formatterRegistry.addFormatterForFieldAnnotation(new Jsr354NumberFormatAnnotationFormatterFactory());
	}

	// Default handling of date-time values

	// just handling JSR-310 specific date and time types
	new DateTimeFormatterRegistrar().registerFormatters(formatterRegistry);

	if (jodaTimePresent) {
		// handles Joda-specific types as well as Date, Calendar, Long
		new JodaTimeFormatterRegistrar().registerFormatters(formatterRegistry);
	}
	else {
		// regular DateFormat-based Date, Calendar, Long converters
		new DateFormatterRegistrar().registerFormatters(formatterRegistry);
	}
}
 
Example 4
Source File: DateFormatterRegistrar.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void registerFormatters(FormatterRegistry registry) {
	addDateConverters(registry);
	registry.addFormatterForFieldAnnotation(new DateTimeFormatAnnotationFormatterFactory());

	// In order to retain back compatibility we only register Date/Calendar
	// types when a user defined formatter is specified (see SPR-10105)
	if (this.dateFormatter != null) {
		registry.addFormatter(this.dateFormatter);
		registry.addFormatterForFieldType(Calendar.class, this.dateFormatter);
	}
}
 
Example 5
Source File: WebConfiguration.java    From java-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void addFormatters(FormatterRegistry registry) {
	registry.addFormatter(DistanceFormatter.INSTANCE);
	registry.addFormatter(PointFormatter.INSTANCE);

	if (!(registry instanceof FormattingConversionService)) {
		return;
	}

	FormattingConversionService conversionService = (FormattingConversionService) registry;

	DomainClassConverter<FormattingConversionService> converter = new DomainClassConverter<FormattingConversionService>(conversionService);
	converter.setApplicationContext(context);
}
 
Example 6
Source File: DateFormatterRegistrar.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void registerFormatters(FormatterRegistry registry) {
	addDateConverters(registry);
	registry.addFormatterForFieldAnnotation(new DateTimeFormatAnnotationFormatterFactory());

	// In order to retain back compatibility we only register Date/Calendar
	// types when a user defined formatter is specified (see SPR-10105)
	if (this.dateFormatter != null) {
		registry.addFormatter(this.dateFormatter);
		registry.addFormatterForFieldType(Calendar.class, this.dateFormatter);
	}
}
 
Example 7
Source File: WebConfiguration.java    From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License 4 votes vote down vote up
@Override
public void addFormatters(FormatterRegistry registry) {
    registry.addFormatter(new BookFormatter(bookRepository));
}
 
Example 8
Source File: WebConfig.java    From Spring with Apache License 2.0 4 votes vote down vote up
@Override
public void addFormatters(FormatterRegistry formatterRegistry) {
    formatterRegistry.addFormatter(dateFormatter());
}
 
Example 9
Source File: FormattingConversionServiceFactoryBeanTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public void registerFormatters(FormatterRegistry registry) {
	registry.addFormatter(new TestBeanFormatter());
}
 
Example 10
Source File: WebConfig.java    From Spring with Apache License 2.0 4 votes vote down vote up
@Override
public void addFormatters(FormatterRegistry formatterRegistry) {
    formatterRegistry.addFormatter(dateFormatter());
}
 
Example 11
Source File: WebConfig.java    From Spring with Apache License 2.0 4 votes vote down vote up
@Override
public void addFormatters(FormatterRegistry formatterRegistry) {
    formatterRegistry.addFormatter(dateFormatter());
}
 
Example 12
Source File: WebConfiguration.java    From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License 4 votes vote down vote up
@Override
public void addFormatters(FormatterRegistry registry) {
    registry.addFormatter(new BookFormatter(bookRepository));
}
 
Example 13
Source File: EtfFormatterRegistrar.java    From etf-webapp with European Union Public License 1.2 4 votes vote down vote up
private static void addConverter(final FormatterRegistry registry, final EtfConverter converter) {
    registry.addConverter(converter.strToTypeConverter());
    registry.addConverter(converter.typeToStrConverter());
    registry.addFormatter(converter);
}
 
Example 14
Source File: WebConfiguration.java    From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License 4 votes vote down vote up
@Override
public void addFormatters(FormatterRegistry registry) {
    registry.addFormatter(new BookFormatter(bookRepository));
}
 
Example 15
Source File: WebConfiguration.java    From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License 4 votes vote down vote up
@Override
public void addFormatters(FormatterRegistry registry) {
    registry.addFormatter(new BookFormatter(bookRepository));
}
 
Example 16
Source File: WebConfiguration.java    From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License 4 votes vote down vote up
@Override
public void addFormatters(FormatterRegistry registry) {
    registry.addFormatter(new BookFormatter(bookRepository));
}
 
Example 17
Source File: WebConfiguration.java    From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License 4 votes vote down vote up
@Override
public void addFormatters(FormatterRegistry registry) {
    registry.addFormatter(new BookFormatter(bookRepository));
}
 
Example 18
Source File: MVCConf.java    From springboot-plus with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void addFormatters(FormatterRegistry registry) {
    registry.addFormatter(new DateFormatter("yyyy-MM-dd HH:mm:ss"));
    registry.addFormatter(new DateFormatter("yyyy-MM-dd"));
}
 
Example 19
Source File: FormattingConversionServiceFactoryBeanTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public void registerFormatters(FormatterRegistry registry) {
	registry.addFormatter(new TestBeanFormatter());
}
 
Example 20
Source File: WebMVCConfig.java    From tutorials with MIT License 4 votes vote down vote up
@Override
@Description("Custom Conversion Service")
public void addFormatters(FormatterRegistry registry) {
    registry.addFormatter(new NameFormatter());
}