List of usage examples for org.springframework.beans.factory.support DefaultListableBeanFactory addPropertyEditorRegistrar
@Override public void addPropertyEditorRegistrar(PropertyEditorRegistrar registrar)
From source file:com.helpinput.propertyeditors.PropertyEditorRegister.java
public static void registerProtertyEditor(DefaultListableBeanFactory dlbf, Class<? extends PropertyEditor> propertyEditorType, Class<?>... targetType) { final Class<?> theTargetType = getTargetType(propertyEditorType, targetType); if (theTargetType == null) return;//from www .j a v a 2s . c om final PropertyEditor propertyEditor = newProtertyEditor(propertyEditorType, theTargetType); if (propertyEditor == null) return; PropertyEditorRegistrar myPropertyEditorRegistrar = new PropertyEditorRegistrar() { public void registerCustomEditors(PropertyEditorRegistry registry) { registry.registerCustomEditor(theTargetType, propertyEditor); } }; dlbf.addPropertyEditorRegistrar(myPropertyEditorRegistrar); }
From source file:org.springframework.beans.factory.ConcurrentBeanFactoryTests.java
@Before public void setUp() throws Exception { Assume.group(TestGroup.PERFORMANCE); DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(factory).loadBeanDefinitions(CONTEXT); factory.addPropertyEditorRegistrar(new PropertyEditorRegistrar() { @Override/*ww w . ja v a 2 s .com*/ public void registerCustomEditors(PropertyEditorRegistry registry) { registry.registerCustomEditor(Date.class, new CustomDateEditor((DateFormat) DATE_FORMAT.clone(), false)); } }); this.factory = factory; }
From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java
@Test public void testCustomEditor() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); lbf.addPropertyEditorRegistrar(new PropertyEditorRegistrar() { @Override/*from w w w .j av a 2 s. co m*/ public void registerCustomEditors(PropertyEditorRegistry registry) { NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN); registry.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, nf, true)); } }); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("myFloat", "1,1"); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); bd.setPropertyValues(pvs); lbf.registerBeanDefinition("testBean", bd); TestBean testBean = (TestBean) lbf.getBean("testBean"); assertTrue(testBean.getMyFloat().floatValue() == 1.1f); }
From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java
@Test public void testCustomEditorWithBeanReference() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); lbf.addPropertyEditorRegistrar(new PropertyEditorRegistrar() { @Override//from w ww .java 2 s . c om public void registerCustomEditors(PropertyEditorRegistry registry) { NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN); registry.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, nf, true)); } }); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("myFloat", new RuntimeBeanReference("myFloat")); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); bd.setPropertyValues(pvs); lbf.registerBeanDefinition("testBean", bd); lbf.registerSingleton("myFloat", "1,1"); TestBean testBean = (TestBean) lbf.getBean("testBean"); assertTrue(testBean.getMyFloat().floatValue() == 1.1f); }