Example usage for org.springframework.beans PropertyEditorRegistrar registerCustomEditors

List of usage examples for org.springframework.beans PropertyEditorRegistrar registerCustomEditors

Introduction

In this page you can find the example usage for org.springframework.beans PropertyEditorRegistrar registerCustomEditors.

Prototype

void registerCustomEditors(PropertyEditorRegistry registry);

Source Link

Document

Register custom java.beans.PropertyEditor PropertyEditors with the given PropertyEditorRegistry .

Usage

From source file:net.solarnetwork.web.support.JSONView.java

private BeanWrapper getPropertyAccessor(Object obj, PropertyEditorRegistrar registrar) {
    BeanWrapper bean = PropertyAccessorFactory.forBeanPropertyAccess(obj);
    if (registrar != null) {
        registrar.registerCustomEditors(bean);
    }//from   w w  w .  jav a  2s.  c om
    return bean;
}

From source file:org.codehaus.groovy.grails.web.binding.GrailsDataBinder.java

/**
 * Collects all PropertyEditorRegistrars in the application context and
 * calls them to register their custom editors
 *
 * @param servletContext/*www .j  a  va2s.  c  om*/
 * @param registry The PropertyEditorRegistry instance
 */
private static void registerCustomEditors(ServletContext servletContext, PropertyEditorRegistry registry) {
    if (servletContext == null) {
        return;
    }

    WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
    if (context == null) {
        return;
    }

    @SuppressWarnings("unchecked")
    Map<String, PropertyEditorRegistrar> editors = (Map<String, PropertyEditorRegistrar>) servletContext
            .getAttribute(PROPERTY_EDITOR_REGISTRARS);
    if (editors == null) {
        editors = context.getBeansOfType(PropertyEditorRegistrar.class);
        if (!Environment.isDevelopmentMode()) {
            servletContext.setAttribute(PROPERTY_EDITOR_REGISTRARS, editors);
        }
    }
    for (PropertyEditorRegistrar editorRegistrar : editors.values()) {
        editorRegistrar.registerCustomEditors(registry);
    }
}