Example usage for org.springframework.format.support FormatterPropertyEditorAdapter FormatterPropertyEditorAdapter

List of usage examples for org.springframework.format.support FormatterPropertyEditorAdapter FormatterPropertyEditorAdapter

Introduction

In this page you can find the example usage for org.springframework.format.support FormatterPropertyEditorAdapter FormatterPropertyEditorAdapter.

Prototype

@SuppressWarnings("unchecked")
public FormatterPropertyEditorAdapter(Formatter<?> formatter) 

Source Link

Document

Create a new FormatterPropertyEditorAdapter for the given Formatter .

Usage

From source file:org.springframework.validation.DataBinder.java

/**
 * Add a custom formatter, applying it to all fields matching the
 * {@link Formatter}-declared type.//  w ww  .ja  va 2 s. c  om
 * <p>Registers a corresponding {@link PropertyEditor} adapter underneath the covers.
 * @param formatter the formatter to add, generically declared for a specific type
 * @since 4.2
 * @see #registerCustomEditor(Class, PropertyEditor)
 */
public void addCustomFormatter(Formatter<?> formatter) {
    FormatterPropertyEditorAdapter adapter = new FormatterPropertyEditorAdapter(formatter);
    getPropertyEditorRegistry().registerCustomEditor(adapter.getFieldType(), adapter);
}

From source file:org.springframework.validation.DataBinder.java

/**
 * Add a custom formatter for the field type specified in {@link Formatter} class,
 * applying it to the specified fields only, if any, or otherwise to all fields.
 * <p>Registers a corresponding {@link PropertyEditor} adapter underneath the covers.
 * @param formatter the formatter to add, generically declared for a specific type
 * @param fields the fields to apply the formatter to, or none if to be applied to all
 * @since 4.2/*from  ww  w . j  a va  2s . c  o  m*/
 * @see #registerCustomEditor(Class, String, PropertyEditor)
 */
public void addCustomFormatter(Formatter<?> formatter, String... fields) {
    FormatterPropertyEditorAdapter adapter = new FormatterPropertyEditorAdapter(formatter);
    Class<?> fieldType = adapter.getFieldType();
    if (ObjectUtils.isEmpty(fields)) {
        getPropertyEditorRegistry().registerCustomEditor(fieldType, adapter);
    } else {
        for (String field : fields) {
            getPropertyEditorRegistry().registerCustomEditor(fieldType, field, adapter);
        }
    }
}

From source file:org.springframework.validation.DataBinder.java

/**
 * Add a custom formatter, applying it to the specified field types only, if any,
 * or otherwise to all fields matching the {@link Formatter}-declared type.
 * <p>Registers a corresponding {@link PropertyEditor} adapter underneath the covers.
 * @param formatter the formatter to add (does not need to generically declare a
 * field type if field types are explicitly specified as parameters)
 * @param fieldTypes the field types to apply the formatter to, or none if to be
 * derived from the given {@link Formatter} implementation class
 * @since 4.2/*  w  ww .  j  a va 2  s . c o m*/
 * @see #registerCustomEditor(Class, PropertyEditor)
 */
public void addCustomFormatter(Formatter<?> formatter, Class<?>... fieldTypes) {
    FormatterPropertyEditorAdapter adapter = new FormatterPropertyEditorAdapter(formatter);
    if (ObjectUtils.isEmpty(fieldTypes)) {
        getPropertyEditorRegistry().registerCustomEditor(adapter.getFieldType(), adapter);
    } else {
        for (Class<?> fieldType : fieldTypes) {
            getPropertyEditorRegistry().registerCustomEditor(fieldType, adapter);
        }
    }
}