expose arrays as comma-delimited element String
This commit is contained in:
parent
784068346d
commit
0543a294ee
|
|
@ -18,6 +18,8 @@ package org.springframework.validation;
|
|||
|
||||
import org.springframework.beans.PropertyAccessException;
|
||||
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Default {@link BindingErrorProcessor} implementation.
|
||||
|
|
@ -65,8 +67,12 @@ public class DefaultBindingErrorProcessor implements BindingErrorProcessor {
|
|||
String field = ex.getPropertyName();
|
||||
String[] codes = bindingResult.resolveMessageCodes(ex.getErrorCode(), field);
|
||||
Object[] arguments = getArgumentsForBindError(bindingResult.getObjectName(), field);
|
||||
Object rejectedValue = ex.getValue();
|
||||
if (rejectedValue != null && rejectedValue.getClass().isArray()) {
|
||||
rejectedValue = StringUtils.arrayToCommaDelimitedString(ObjectUtils.toObjectArray(rejectedValue));
|
||||
}
|
||||
bindingResult.addError(new FieldError(
|
||||
bindingResult.getObjectName(), field, ex.getValue(), true,
|
||||
bindingResult.getObjectName(), field, rejectedValue, true,
|
||||
codes, arguments, ex.getLocalizedMessage()));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,14 +16,6 @@
|
|||
|
||||
package org.springframework.web.servlet.mvc.annotation;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.io.Writer;
|
||||
|
|
@ -43,7 +35,6 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
|
|
@ -54,8 +45,9 @@ import javax.servlet.http.HttpSession;
|
|||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
|
||||
import org.springframework.aop.interceptor.SimpleTraceInterceptor;
|
||||
import org.springframework.aop.support.DefaultPointcutAdvisor;
|
||||
|
|
@ -90,6 +82,7 @@ import org.springframework.util.SerializationTestUtils;
|
|||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.FieldError;
|
||||
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.annotation.CookieValue;
|
||||
|
|
@ -1303,6 +1296,9 @@ public class ServletAnnotationControllerTests {
|
|||
|
||||
@RequestMapping("/myPath.do")
|
||||
public String myHandle(@ModelAttribute("myCommand") TestBean tb, BindingResult errors, ModelMap model) {
|
||||
FieldError error = errors.getFieldError("age");
|
||||
assertNotNull("Must have field error for age property", error);
|
||||
assertEquals("value2", error.getRejectedValue());
|
||||
if (!model.containsKey("myKey")) {
|
||||
model.addAttribute("myKey", "myValue");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue