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

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

Introduction

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

Prototype

public Class<?> getFieldType() 

Source Link

Document

Determine the Formatter -declared field type.

Usage

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

/**
 * Add a custom formatter, applying it to all fields matching the
 * {@link Formatter}-declared type./*from  w w w.  j a va2 s .com*/
 * <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/*  www  .ja  v  a  2 s .c om*/
 * @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//from w  w  w  .ja v a  2  s  . com
 * @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);
        }
    }
}