|
22 | 22 | import java.io.ByteArrayOutputStream;
|
23 | 23 | import java.io.ObjectInputStream;
|
24 | 24 | import java.io.ObjectOutputStream;
|
| 25 | +import java.text.ParseException; |
25 | 26 | import java.util.AbstractList;
|
26 | 27 | import java.util.ArrayList;
|
27 | 28 | import java.util.Collection;
|
|
52 | 53 | import org.springframework.context.support.ResourceBundleMessageSource;
|
53 | 54 | import org.springframework.context.support.StaticMessageSource;
|
54 | 55 | import org.springframework.core.convert.support.ConversionServiceFactory;
|
| 56 | +import org.springframework.format.Formatter; |
55 | 57 | import org.springframework.format.number.NumberFormatter;
|
56 | 58 | import org.springframework.format.support.FormattingConversionService;
|
57 | 59 | import org.springframework.util.StringUtils;
|
@@ -373,6 +375,28 @@ public void testBindingErrorWithFormatter() {
|
373 | 375 | }
|
374 | 376 | }
|
375 | 377 |
|
| 378 | + public void testBindingErrorWithStringFormatter() { |
| 379 | + TestBean tb = new TestBean(); |
| 380 | + DataBinder binder = new DataBinder(tb); |
| 381 | + FormattingConversionService conversionService = new FormattingConversionService(); |
| 382 | + ConversionServiceFactory.addDefaultConverters(conversionService); |
| 383 | + conversionService.addFormatterForFieldType(String.class, new Formatter<String>() { |
| 384 | + public String parse(String text, Locale locale) throws ParseException { |
| 385 | + throw new ParseException(text, 0); |
| 386 | + } |
| 387 | + public String print(String object, Locale locale) { |
| 388 | + return object; |
| 389 | + } |
| 390 | + }); |
| 391 | + binder.setConversionService(conversionService); |
| 392 | + MutablePropertyValues pvs = new MutablePropertyValues(); |
| 393 | + pvs.add("name", "test"); |
| 394 | + |
| 395 | + binder.bind(pvs); |
| 396 | + assertTrue(binder.getBindingResult().hasFieldErrors("name")); |
| 397 | + assertEquals("test", binder.getBindingResult().getFieldValue("name")); |
| 398 | + } |
| 399 | + |
376 | 400 | public void testBindingWithFormatterAgainstList() {
|
377 | 401 | BeanWithIntegerList tb = new BeanWithIntegerList();
|
378 | 402 | DataBinder binder = new DataBinder(tb);
|
|
0 commit comments