From 835ebfcd250b0bb9ef920d976392490cf8c8d301 Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Thu, 3 Sep 2009 03:36:57 +0000 Subject: [PATCH] setting up FormatterRegistrY --- spring-framework-reference/src/validation.xml | 53 +++++++++++++++++-- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/spring-framework-reference/src/validation.xml b/spring-framework-reference/src/validation.xml index 3eb61ee0908..8ff8643bcbe 100644 --- a/spring-framework-reference/src/validation.xml +++ b/spring-framework-reference/src/validation.xml @@ -951,7 +951,7 @@ public final class DateFormatter implements Formatter {
- @Formatted Annotation + @Formatted The @Formatted annotation allows you to easily configure the Formatter implementation to use for one or more of your model classes. To use this feature, simply annotate your class as @Formatted and specify the Formatter implementation to use as the annotation value: @@ -1044,22 +1044,67 @@ public interface FormatterRegistry {
Configuring a FormatterRegistry + A FormatterRegistry is a stateless object designed to be instantiated on application startup, then shared between multiple threads. + In a Spring MVC application, you configure a FormatterRegistry as a property of the WebBinderInitializer. + The FormatterRegistry will then be configured whenever a DataBinder is created by Spring MVC to bind model properties and render field values. + If no FormatterRegistry is configured, the original PropertyEditor-based system is used. + To register a FormatterRegistry with Spring MVC, simply configure it as a property of a custom WebBindingInitializer injected into the + Spring MVC AnnotationMethodHandlerAdapter. - + + + + + + + + + + + + + + + + + + + + + +]]> + + See the JavaDocs for GenericFormatterRegistry for more configuration options. +
-
+
Registering field-specific Formatters + In most cases, configuring a shared FormatterRegistry that selects Formatters based on model property type or annotation is sufficient. + When sufficient, special @Controller @InitBinder callbacks are NOT needed to apply custom formatting logic. + However, there are cases where field-specific formatting should be configured on a Controller-by-Controller basis. + For example, you may need to format a specific Date field in a way that differs from all the other Date fields in your application. + To apply a Formatter to a single field, create an @InitBinder callback on your @Controller, then call binder.registerFormatter(String, Formatter): + + This applies the Formatter to the specific field, overriding any Formatter that would have been applied by type or annotation. +