@@ -1831,8 +1831,8 @@ arguments of annotated handler methods.
1831
1831
1832
1832
Such init-binder methods support all arguments that `@RequestMapping` supports, except
1833
1833
for command/form objects and corresponding validation result objects. Init-binder
1834
- methods must not have a return value. Thus, they are usually declared as `void`. Typical
1835
- arguments include `WebDataBinder` in combination with `WebRequest` or
1834
+ methods must not have a return value. Thus, they are usually declared as `void`.
1835
+ Typical arguments include `WebDataBinder` in combination with `WebRequest` or
1836
1836
`java.util.Locale`, allowing code to register context-specific editors.
1837
1837
1838
1838
The following example demonstrates the use of `@InitBinder` to configure a
@@ -1852,7 +1852,27 @@ The following example demonstrates the use of `@InitBinder` to configure a
1852
1852
}
1853
1853
1854
1854
// ...
1855
+ }
1856
+ ----
1857
+
1858
+ Alternatively, as of Spring 4.2, consider using `addCustomFormatter` to specify
1859
+ `Formatter` implementations instead of `PropertyEditor` instances. This is
1860
+ particularly useful if you happen to have a `Formatter`-based setup in a shared
1861
+ `FormattingConversionService` as well, with the same approach to be reused for
1862
+ controller-specific tweaking of the binding rules.
1863
+
1864
+ [source,java,indent=0]
1865
+ [subs="verbatim,quotes"]
1866
+ ----
1867
+ @Controller
1868
+ public class MyFormController {
1855
1869
1870
+ **@InitBinder**
1871
+ public void initBinder(WebDataBinder binder) {
1872
+ binder.addCustomFormatter(new DateFormatter("yyyy-MM-dd"));
1873
+ }
1874
+
1875
+ // ...
1856
1876
}
1857
1877
----
1858
1878
0 commit comments