polish
This commit is contained in:
@@ -120,10 +120,11 @@ public class Binder<T> {
|
|||||||
.entrySet()) {
|
.entrySet()) {
|
||||||
Binding binding = getBinding(entry.getKey());
|
Binding binding = getBinding(entry.getKey());
|
||||||
Object value = entry.getValue();
|
Object value = entry.getValue();
|
||||||
if (value instanceof String[]) {
|
if (value instanceof String) {
|
||||||
binding.setValues((String[])value);
|
|
||||||
} else if (value instanceof String) {
|
|
||||||
binding.setValue((String)entry.getValue());
|
binding.setValue((String)entry.getValue());
|
||||||
|
}
|
||||||
|
else if (value instanceof String[]) {
|
||||||
|
binding.setValues((String[])value);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Illegal argument " + value);
|
throw new IllegalArgumentException("Illegal argument " + value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import org.junit.Test;
|
|||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
import org.springframework.ui.format.DateFormatter;
|
import org.springframework.ui.format.DateFormatter;
|
||||||
import org.springframework.ui.format.number.CurrencyFormatter;
|
import org.springframework.ui.format.number.CurrencyFormatter;
|
||||||
|
import org.springframework.ui.format.number.IntegerFormatter;
|
||||||
|
|
||||||
public class BinderTests {
|
public class BinderTests {
|
||||||
|
|
||||||
@@ -135,6 +136,16 @@ public class BinderTests {
|
|||||||
assertEquals("$23.56", b.getValue());
|
assertEquals("$23.56", b.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getBindingCustomFormatterRequiringTypeCoersion() {
|
||||||
|
Binder<TestBean> binder = new Binder<TestBean>(new TestBean());
|
||||||
|
// IntegerFormatter formats Longs, so conversion from Integer -> Long is performed
|
||||||
|
binder.add(new BindingConfiguration("integer", new IntegerFormatter()));
|
||||||
|
Binding b = binder.getBinding("integer");
|
||||||
|
b.setValue("2,300");
|
||||||
|
assertEquals("2,300", b.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getBindingMultiValued() {
|
public void getBindingMultiValued() {
|
||||||
Binder<TestBean> binder = new Binder<TestBean>(new TestBean());
|
Binder<TestBean> binder = new Binder<TestBean>(new TestBean());
|
||||||
|
|||||||
Reference in New Issue
Block a user