List of usage examples for org.springframework.beans PropertyEditorRegistrar PropertyEditorRegistrar
PropertyEditorRegistrar
From source file:org.duracloud.account.config.WebConfig.java
@Override @Bean//from w w w. ja v a 2 s . c o m public RequestMappingHandlerAdapter requestMappingHandlerAdapter() { RequestMappingHandlerAdapter adapter = super.requestMappingHandlerAdapter(); ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) adapter .getWebBindingInitializer(); PropertyEditorRegistrar propertyEditorRegistrar = new PropertyEditorRegistrar() { @Override public void registerCustomEditors(PropertyEditorRegistry registry) { //Trim strings before setting values on all form beans. registry.registerCustomEditor(Object.class, new StringTrimmerEditor(true)); } }; initializer.setPropertyEditorRegistrar(propertyEditorRegistrar); return adapter; }
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 w w w .j a va 2s . c o m*/ 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/*from www . j av a2 s .co m*/ 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 ww. ja v 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 www . ja v a 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); }