Package org.springframework.beans
Class DirectFieldAccessor
- All Implemented Interfaces:
ConfigurablePropertyAccessor
,PropertyAccessor
,PropertyEditorRegistry
,TypeConverter
public class DirectFieldAccessor extends AbstractNestablePropertyAccessor
ConfigurablePropertyAccessor
implementation that directly accesses instance fields. Allows for direct binding to fields instead of going through JavaBean setters.As of Spring 4.2, the vast majority of the
BeanWrapper
features have been merged toAbstractPropertyAccessor
, which means that property traversal as well as collections and map access is now supported here as well.A DirectFieldAccessor's default for the "extractOldValueForEditor" setting is "true", since a field can always be read without side effects.
- Since:
- 2.0
- Author:
- Juergen Hoeller, Stephane Nicoll
- See Also:
AbstractPropertyAccessor.setExtractOldValueForEditor(boolean)
,BeanWrapper
,DirectFieldBindingResult
,DataBinder.initDirectFieldAccess()
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.beans.AbstractNestablePropertyAccessor
AbstractNestablePropertyAccessor.PropertyHandler, AbstractNestablePropertyAccessor.PropertyTokenHolder
Field Summary
Fields inherited from interface org.springframework.beans.PropertyAccessor
NESTED_PROPERTY_SEPARATOR, NESTED_PROPERTY_SEPARATOR_CHAR, PROPERTY_KEY_PREFIX, PROPERTY_KEY_PREFIX_CHAR, PROPERTY_KEY_SUFFIX, PROPERTY_KEY_SUFFIX_CHAR
Constructor Summary
Constructors Modifier Constructor Description DirectFieldAccessor(Object object)
Create a new DirectFieldAccessor for the given object.protected
DirectFieldAccessor(Object object, String nestedPath, DirectFieldAccessor parent)
Create a new DirectFieldAccessor for the given object, registering a nested path that the object is in.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected NotWritablePropertyException
createNotWritablePropertyException(String propertyName)
Create aNotWritablePropertyException
for the specified property.protected org.springframework.beans.DirectFieldAccessor.FieldPropertyHandler
getLocalPropertyHandler(String propertyName)
Return aAbstractNestablePropertyAccessor.PropertyHandler
for the specified localpropertyName
.protected DirectFieldAccessor
newNestedPropertyAccessor(Object object, String nestedPath)
Create a new nested property accessor instance.Methods inherited from class org.springframework.beans.AbstractNestablePropertyAccessor
convertForProperty, getAutoGrowCollectionLimit, getFinalPath, getNestedPath, getPropertyAccessorForPropertyPath, getPropertyHandler, getPropertyType, getPropertyTypeDescriptor, getPropertyValue, getPropertyValue, getRootClass, getRootInstance, getWrappedClass, getWrappedInstance, isReadableProperty, isWritableProperty, setAutoGrowCollectionLimit, setPropertyValue, setPropertyValue, setPropertyValue, setWrappedInstance, setWrappedInstance, toString
Methods inherited from class org.springframework.beans.AbstractPropertyAccessor
isAutoGrowNestedPaths, isExtractOldValueForEditor, setAutoGrowNestedPaths, setExtractOldValueForEditor, setPropertyValues, setPropertyValues, setPropertyValues, setPropertyValues
Methods inherited from class org.springframework.beans.TypeConverterSupport
convertIfNecessary, convertIfNecessary, convertIfNecessary
Methods inherited from class org.springframework.beans.PropertyEditorRegistrySupport
copyCustomEditorsTo, copyDefaultEditorsTo, findCustomEditor, getConversionService, getDefaultEditor, guessPropertyTypeFromEditors, hasCustomEditorForElement, overrideDefaultEditor, registerCustomEditor, registerCustomEditor, registerDefaultEditors, setConversionService, useConfigValueEditors
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.beans.ConfigurablePropertyAccessor
getConversionService, setConversionService
Methods inherited from interface org.springframework.beans.PropertyEditorRegistry
findCustomEditor, registerCustomEditor, registerCustomEditor
Methods inherited from interface org.springframework.beans.TypeConverter
convertIfNecessary, convertIfNecessary, convertIfNecessary
Constructor Detail
DirectFieldAccessor
public DirectFieldAccessor(Object object)
Create a new DirectFieldAccessor for the given object.- Parameters:
object
- the object wrapped by this DirectFieldAccessor
DirectFieldAccessor
protected DirectFieldAccessor(Object object, String nestedPath, DirectFieldAccessor parent)
Create a new DirectFieldAccessor for the given object, registering a nested path that the object is in.- Parameters:
object
- the object wrapped by this DirectFieldAccessornestedPath
- the nested path of the objectparent
- the containing DirectFieldAccessor (must not benull
)
Method Detail
getLocalPropertyHandler
protected org.springframework.beans.DirectFieldAccessor.FieldPropertyHandler getLocalPropertyHandler(String propertyName)
Description copied from class:AbstractNestablePropertyAccessor
Return aAbstractNestablePropertyAccessor.PropertyHandler
for the specified localpropertyName
. Only used to reach a property available in the current context.- Specified by:
getLocalPropertyHandler
in classAbstractNestablePropertyAccessor
- Parameters:
propertyName
- the name of a local property- Returns:
- the handler for that property or
null
if it has not been found
newNestedPropertyAccessor
protected DirectFieldAccessor newNestedPropertyAccessor(Object object, String nestedPath)
Description copied from class:AbstractNestablePropertyAccessor
Create a new nested property accessor instance. Can be overridden in subclasses to create a PropertyAccessor subclass.- Specified by:
newNestedPropertyAccessor
in classAbstractNestablePropertyAccessor
- Parameters:
object
- object wrapped by this PropertyAccessornestedPath
- the nested path of the object- Returns:
- the nested PropertyAccessor instance
createNotWritablePropertyException
protected NotWritablePropertyException createNotWritablePropertyException(String propertyName)
Description copied from class:AbstractNestablePropertyAccessor
Create aNotWritablePropertyException
for the specified property.- Specified by:
createNotWritablePropertyException
in classAbstractNestablePropertyAccessor