Top Description Fields Constructors Methods
org.springframework.beans.factory.config

public Class CustomEditorConfigurer

extends Object
implements BeanFactoryPostProcessor, Ordered
Class Inheritance
All Implemented Interfaces
org.springframework.core.Ordered, org.springframework.beans.factory.config.BeanFactoryPostProcessor
Imports
java.beans.PropertyEditor, java.util.Map, org.apache.commons.logging.Log, .LogFactory, org.springframework.beans.BeansException, .PropertyEditorRegistrar, org.springframework.core.Ordered, org.springframework.lang.Nullable, org.springframework.util.ClassUtils

BeanFactoryPostProcessor implementation that allows for convenient registration of custom property editors.

In case you want to register PropertyEditor instances, the recommended usage as of Spring 2.0 is to use custom PropertyEditorRegistrar implementations that in turn register any desired editor instances on a given registry. Each PropertyEditorRegistrar can register any number of custom editors.

<bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
  <property name="propertyEditorRegistrars">
    <list>
      <bean class="mypackage.MyCustomDateEditorRegistrar"/>
      <bean class="mypackage.MyObjectEditorRegistrar"/>
    </list>
  </property>
</bean>

It's perfectly fine to register PropertyEditor classes via the customEditors property. Spring will create fresh instances of them for each editing attempt then:

<bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
  <property name="customEditors">
    <map>
      <entry key="java.util.Date" value="mypackage.MyCustomDateEditor"/>
      <entry key="mypackage.MyObject" value="mypackage.MyObjectEditor"/>
    </map>
  </property>
</bean>

Note, that you shouldn't register PropertyEditor bean instances via the customEditors property as PropertyEditors are stateful and the instances will then have to be synchronized for every editing attempt. In case you need control over the instantiation process of PropertyEditors, use a PropertyEditorRegistrar to register them.

Also supports "java.lang.String[]"-style array class names and primitive class names (e.g. "boolean"). Delegates to ClassUtils for actual class name resolution.

Note

Custom property editors registered with this configurer do not apply to data binding. Custom editors for data binding need to be registered on the org.springframework.validation.DataBinder: Use a common base class or delegate to common PropertyEditorRegistrar implementations to reuse editor registration there.

Author
Juergen Hoeller
Since
27.02.2004
See Also
java.beans.PropertyEditor, org.springframework.beans.PropertyEditorRegistrar, ConfigurableBeanFactory#addPropertyEditorRegistrar, ConfigurableBeanFactory#registerCustomEditor, org.springframework.validation.DataBinder#registerCustomEditor

Field Summary

Modifier and TypeField and Description
private Map<Class<?>, Class<? extends PropertyEditor>>
protected final Log
private int
private PropertyEditorRegistrar[]

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public int
getOrder()

Implements org.springframework.core.Ordered.getOrder.

Get the order value of this object.

public void
postProcessBeanFactory(ConfigurableListableBeanFactory
the bean factory used by the application context
beanFactory
)

Implements org.springframework.beans.factory.config.BeanFactoryPostProcessor.postProcessBeanFactory.

Modify the application context's internal bean factory after its standard initialization.

public void
setCustomEditors(Map<Class<?>, Class<? extends PropertyEditor>> customEditors)

Specify the custom editors to register via a Map, using the class name of the required type as the key and the class name of the associated PropertyEditor as value.

public void
setOrder(int order)

public void
setPropertyEditorRegistrars(PropertyEditorRegistrar[] propertyEditorRegistrars)

Specify the PropertyEditorRegistrars to apply to beans defined within the current application context.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

customEditorsback to summary
private Map<Class<?>, Class<? extends PropertyEditor>> customEditors
Annotations
@Nullable
loggerback to summary
protected final Log logger
orderback to summary
private int order
propertyEditorRegistrarsback to summary
private PropertyEditorRegistrar[] propertyEditorRegistrars
Annotations
@Nullable

Constructor Detail

CustomEditorConfigurerback to summary
public CustomEditorConfigurer()

Method Detail

getOrderback to summary
public int getOrder()

Implements org.springframework.core.Ordered.getOrder.

Doc from org.springframework.core.Ordered.getOrder.

Get the order value of this object.

Higher values are interpreted as lower priority. As a consequence, the object with the lowest value has the highest priority (somewhat analogous to Servlet load-on-startup values).

Same order values will result in arbitrary sort positions for the affected objects.

Returns:int

the order value

Annotations
@Override
postProcessBeanFactoryback to summary
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException

Implements org.springframework.beans.factory.config.BeanFactoryPostProcessor.postProcessBeanFactory.

Doc from org.springframework.beans.factory.config.BeanFactoryPostProcessor.postProcessBeanFactory.

Modify the application context's internal bean factory after its standard initialization. All bean definitions will have been loaded, but no beans will have been instantiated yet. This allows for overriding or adding properties even to eager-initializing beans.

Parameters
beanFactory:ConfigurableListableBeanFactory

the bean factory used by the application context

Annotations
@Override
Exceptions
BeansException:
in case of errors
setCustomEditorsback to summary
public void setCustomEditors(Map<Class<?>, Class<? extends PropertyEditor>> customEditors)

Specify the custom editors to register via a Map, using the class name of the required type as the key and the class name of the associated PropertyEditor as value.

See Also
ConfigurableListableBeanFactory#registerCustomEditor
setOrderback to summary
public void setOrder(int order)
setPropertyEditorRegistrarsback to summary
public void setPropertyEditorRegistrars(PropertyEditorRegistrar[] propertyEditorRegistrars)

Specify the PropertyEditorRegistrars to apply to beans defined within the current application context.

This allows for sharing PropertyEditorRegistrars with DataBinders, etc. Furthermore, it avoids the need for synchronization on custom editors: A PropertyEditorRegistrar will always create fresh editor instances for each bean creation attempt.

See Also
ConfigurableListableBeanFactory#addPropertyEditorRegistrar