Class CustomEditorConfigurer
- java.lang.Object
- org.springframework.beans.factory.config.CustomEditorConfigurer
- All Implemented Interfaces:
BeanFactoryPostProcessor,Ordered
public class CustomEditorConfigurer extends Object implements BeanFactoryPostProcessor, Ordered
BeanFactoryPostProcessorimplementation that allows for convenient registration of customproperty editors.In case you want to register
PropertyEditorinstances, the recommended usage as of Spring 2.0 is to use customPropertyEditorRegistrarimplementations that in turn register any desired editor instances on a givenregistry. 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
PropertyEditorclasses via thecustomEditorsproperty. 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
PropertyEditorbean instances via thecustomEditorsproperty asPropertyEditors are stateful and the instances will then have to be synchronized for every editing attempt. In case you need control over the instantiation process ofPropertyEditors, use aPropertyEditorRegistrarto register them.Also supports "java.lang.String[]"-style array class names and primitive class names (e.g. "boolean"). Delegates to
ClassUtilsfor 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
DataBinder: Use a common base class or delegate to common PropertyEditorRegistrar implementations to reuse editor registration there.- Since:
- 27.02.2004
- Author:
- Juergen Hoeller
- See Also:
PropertyEditor,PropertyEditorRegistrar,ConfigurableBeanFactory.addPropertyEditorRegistrar(org.springframework.beans.PropertyEditorRegistrar),ConfigurableBeanFactory.registerCustomEditor(java.lang.Class<?>, java.lang.Class<? extends java.beans.PropertyEditor>),DataBinder.registerCustomEditor(java.lang.Class<?>, java.beans.PropertyEditor)
Field Summary
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor Summary
Constructors Constructor Description CustomEditorConfigurer()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetOrder()Get the order value of this object.voidpostProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)Modify the application context's internal bean factory after its standard initialization.voidsetCustomEditors(Map<Class<?>,Class<? extends PropertyEditor>> customEditors)Specify the custom editors to register via aMap, using the class name of the required type as the key and the class name of the associatedPropertyEditoras value.voidsetOrder(int order)voidsetPropertyEditorRegistrars(PropertyEditorRegistrar[] propertyEditorRegistrars)Specify thePropertyEditorRegistrarsto apply to beans defined within the current application context.
Constructor Detail
CustomEditorConfigurer
public CustomEditorConfigurer()
Method Detail
setOrder
public void setOrder(int order)
getOrder
public int getOrder()
Description copied from interface:OrderedGet 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-startupvalues).Same order values will result in arbitrary sort positions for the affected objects.
- Specified by:
getOrderin interfaceOrdered- Returns:
- the order value
- See Also:
Ordered.HIGHEST_PRECEDENCE,Ordered.LOWEST_PRECEDENCE
setPropertyEditorRegistrars
public void setPropertyEditorRegistrars(PropertyEditorRegistrar[] propertyEditorRegistrars)
Specify thePropertyEditorRegistrarsto apply to beans defined within the current application context.This allows for sharing
PropertyEditorRegistrarswithDataBinders, etc. Furthermore, it avoids the need for synchronization on custom editors: APropertyEditorRegistrarwill always create fresh editor instances for each bean creation attempt.
setCustomEditors
public void setCustomEditors(Map<Class<?>,Class<? extends PropertyEditor>> customEditors)
Specify the custom editors to register via aMap, using the class name of the required type as the key and the class name of the associatedPropertyEditoras value.
postProcessBeanFactory
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException
Description copied from interface:BeanFactoryPostProcessorModify 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.- Specified by:
postProcessBeanFactoryin interfaceBeanFactoryPostProcessor- Parameters:
beanFactory- the bean factory used by the application context- Throws:
BeansException- in case of errors