diff --git a/org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericBinder.java b/org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericBinder.java index 20ffbf9d0c..0b0fccaf59 100644 --- a/org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericBinder.java +++ b/org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericBinder.java @@ -756,7 +756,6 @@ public class GenericBinder implements Binder { if (cause instanceof SpelEvaluationException && ((SpelEvaluationException) cause).getMessageCode() == SpelMessage.TYPE_CONVERSION_ERROR) { // TODO this could be a ConverterExecutorNotFoundException if no suitable converter was found - cause.getCause().printStackTrace(); ConversionFailedException failure = (ConversionFailedException) cause.getCause(); MessageBuilder builder = new MessageBuilder(messageSource); builder.code("conversionFailed"); diff --git a/org.springframework.context/src/test/java/org/springframework/ui/binding/support/GenericBinderTests.java b/org.springframework.context/src/test/java/org/springframework/ui/binding/support/GenericBinderTests.java index 4ded264f3f..a81a09885a 100644 --- a/org.springframework.context/src/test/java/org/springframework/ui/binding/support/GenericBinderTests.java +++ b/org.springframework.context/src/test/java/org/springframework/ui/binding/support/GenericBinderTests.java @@ -242,7 +242,7 @@ public class GenericBinderTests { assertEquals("FL", bean.addresses.get(0).state); assertEquals("35452", bean.addresses.get(0).zip); } - + @Test public void bindToListElements() { binder.addBinding("addresses"); @@ -280,7 +280,7 @@ public class GenericBinderTests { } @Test - public void getListAsSingleValue() { + public void getListAsSingleString() { binder.addBinding("addresses"); binder.registerFormatter(new GenericCollectionPropertyType(List.class, Address.class), new AddressListFormatter()); Address address1 = new Address(); @@ -341,6 +341,63 @@ public class GenericBinderTests { assertEquals(12, results.size()); } + @Test + @Ignore + public void bindToMap() { + binder.addBinding("favoriteFoodsByGroup"); + Map values = new LinkedHashMap(); + values.put("favoriteFoodsByGroup", new String[] { "DAIRY=Milk", "FRUIT=Peaches", "MEAT=Ham" }); + BindingResults results = binder.bind(values); + System.out.println(results); + Assert.assertEquals(3, bean.favoriteFoodsByGroup.size()); + assertEquals("Milk", bean.favoriteFoodsByGroup.get(FoodGroup.DAIRY)); + assertEquals("Peaches", bean.favoriteFoodsByGroup.get(FoodGroup.FRUIT)); + assertEquals("Ham", bean.favoriteFoodsByGroup.get(FoodGroup.MEAT)); + } + + @Test + @Ignore + public void bindToMapElements() { + binder.addBinding("favoriteFoodsByGroup"); + Map values = new LinkedHashMap(); + values.put("favoriteFoodsByGroup[DAIRY]", "Milk"); + values.put("favoriteFoodsByGroup[FRUIT]", "Peaches"); + values.put("favoriteFoodsByGroup[MEAT]", "Ham"); + BindingResults results = binder.bind(values); + System.out.println(results); + Assert.assertEquals(3, bean.favoriteFoodsByGroup.size()); + assertEquals("Milk", bean.favoriteFoodsByGroup.get(FoodGroup.DAIRY)); + assertEquals("Peaches", bean.favoriteFoodsByGroup.get(FoodGroup.FRUIT)); + assertEquals("Ham", bean.favoriteFoodsByGroup.get(FoodGroup.MEAT)); + } + + @Test + @Ignore + public void bindToMapSingleString() { + binder.addBinding("favoriteFoodsByGroup"); + Map values = new LinkedHashMap(); + values.put("favoriteFoodsByGroup", "DAIRY=Milk FRUIT=Peaches MEAT=Ham"); + BindingResults results = binder.bind(values); + System.out.println(results); + Assert.assertEquals(3, bean.favoriteFoodsByGroup.size()); + assertEquals("Milk", bean.favoriteFoodsByGroup.get(FoodGroup.DAIRY)); + assertEquals("Peaches", bean.favoriteFoodsByGroup.get(FoodGroup.FRUIT)); + assertEquals("Ham", bean.favoriteFoodsByGroup.get(FoodGroup.MEAT)); + } + + @Test + @Ignore + public void getMapAsSingleString() { + binder.addBinding("favoriteFoodsByGroup"); + Map foods = new LinkedHashMap(); + foods.put(FoodGroup.DAIRY, "Milk"); + foods.put(FoodGroup.FRUIT, "Peaches"); + foods.put(FoodGroup.MEAT, "Ham"); + bean.favoriteFoodsByGroup = foods; + String value = binder.getBinding("favoriteFoodsByGroup").getValue(); + assertEquals("DAIRY=Milk FRUIT=Peaches MEAT=Ham", value); + } + @Test public void formatPossibleValue() { binder.addBinding("currency").formatWith(new CurrencyFormatter());