@ -1,5 +1,5 @@
/ *
/ *
* Copyright 2002 - 2013 the original author or authors .
* Copyright 2002 - 2016 the original author or authors .
*
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* you may not use this file except in compliance with the License .
@ -17,11 +17,13 @@
package org.springframework.web.bind ;
package org.springframework.web.bind ;
import java.lang.reflect.Array ;
import java.lang.reflect.Array ;
import java.util.Collection ;
import java.util.List ;
import java.util.List ;
import java.util.Map ;
import java.util.Map ;
import org.springframework.beans.MutablePropertyValues ;
import org.springframework.beans.MutablePropertyValues ;
import org.springframework.beans.PropertyValue ;
import org.springframework.beans.PropertyValue ;
import org.springframework.core.CollectionFactory ;
import org.springframework.validation.DataBinder ;
import org.springframework.validation.DataBinder ;
import org.springframework.web.multipart.MultipartFile ;
import org.springframework.web.multipart.MultipartFile ;
@ -40,6 +42,7 @@ import org.springframework.web.multipart.MultipartFile;
*
*
* @author Juergen Hoeller
* @author Juergen Hoeller
* @author Scott Andrews
* @author Scott Andrews
* @author Brian Clozel
* @since 1 . 2
* @since 1 . 2
* @see # registerCustomEditor
* @see # registerCustomEditor
* @see # setAllowedFields
* @see # setAllowedFields
@ -243,26 +246,41 @@ public class WebDataBinder extends DataBinder {
/ * *
/ * *
* Determine an empty value for the specified field .
* Determine an empty value for the specified field .
* < p > Default implementation returns { @code Boolean . FALSE }
* < p > Default implementation returns :
* for boolean fields and an empty array of array types .
* < ul >
* Else , { @code null } is used as default .
* < li > { @code Boolean . FALSE } for boolean fields
* < li > an empty array for array types
* < li > Collection implementations for Collection types
* < li > Map implementations for Map types
* < li > else , { @code null } is used as default
* < / ul >
* @param field the name of the field
* @param field the name of the field
* @param fieldType the type of the field
* @param fieldType the type of the field
* @return the empty value ( for most fields : null )
* @return the empty value ( for most fields : null )
* /
* /
protected Object getEmptyValue ( String field , Class < ? > fieldType ) {
protected Object getEmptyValue ( String field , Class < ? > fieldType ) {
if ( fieldType ! = null & & boolean . class = = fieldType | | Boolean . class = = fieldType ) {
if ( fieldType ! = null ) {
// Special handling of boolean property.
try {
return Boolean . FALSE ;
if ( boolean . class = = fieldType | | Boolean . class = = fieldType ) {
}
// Special handling of boolean property.
else if ( fieldType ! = null & & fieldType . isArray ( ) ) {
return Boolean . FALSE ;
// Special handling of array property.
}
return Array . newInstance ( fieldType . getComponentType ( ) , 0 ) ;
else if ( fieldType . isArray ( ) ) {
}
// Special handling of array property.
else {
return Array . newInstance ( fieldType . getComponentType ( ) , 0 ) ;
// Default value: try null.
}
return null ;
else if ( Collection . class . isAssignableFrom ( fieldType ) ) {
return CollectionFactory . createCollection ( fieldType , 0 ) ;
}
else if ( Map . class . isAssignableFrom ( fieldType ) ) {
return CollectionFactory . createMap ( fieldType , 0 ) ;
}
} catch ( IllegalArgumentException exc ) {
return null ;
}
}
}
// Default value: try null.
return null ;
}
}
/ * *
/ * *