Browse Source

added special handling of String array values for required fields, e.g. for WebRequestDataBinder (SPR-6552)

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@2660 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Juergen Hoeller 16 years ago
parent
commit
f22aebd590
  1. 13
      org.springframework.context/src/main/java/org/springframework/validation/DataBinder.java

13
org.springframework.context/src/main/java/org/springframework/validation/DataBinder.java

@ -623,8 +623,17 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { @@ -623,8 +623,17 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
}
for (String field : requiredFields) {
PropertyValue pv = propertyValues.get(field);
if (pv == null || pv.getValue() == null ||
(pv.getValue() instanceof String && !StringUtils.hasText((String) pv.getValue()))) {
boolean empty = (pv == null || pv.getValue() == null);
if (!empty) {
if (pv.getValue() instanceof String) {
empty = !StringUtils.hasText((String) pv.getValue());
}
else if (pv.getValue() instanceof String[]) {
String[] values = (String[]) pv.getValue();
empty = (values.length == 0 || !StringUtils.hasText(values[0]));
}
}
if (empty) {
// Use bind error processor to create FieldError.
getBindingErrorProcessor().processMissingFieldError(field, getInternalBindingResult());
// Remove property from property values to bind:

Loading…
Cancel
Save