Skip to content

UI Formatter SPI as an alternative to PropertyEditors [SPR-6012] #10681

@spring-projects-issues

Description

@spring-projects-issues

Keith Donald opened SPR-6012 and commented

Characteristics of the new SPI:

  • Simpler than PropertyEditors, with no java.beans, awt, concrete inheritance, and Swing dependency.
  • Instances can be shared / formatting logic is thread safe
  • Typesafe through use of generics

API proposal:

Package: org.springframework.ui.format


/**
 * Formats objects of type T for display.
 * @author Keith Donald
 * @since 3.0 
 * @param <T> the type of object this formatter can format
 */
public interface Formatter<T> {
	
	/**
	 * Format the object of type T for display.
	 * @param object the object to format
	 * @param locale the user's locale
	 * @return the formatted display string
	 */
	String format(T object, Locale locale);
	
	/**
	 * Parse an object from its formatted representation.
	 * @param formatted a formatted representation
	 * @param locale the user's locale
	 * @return the parsed object
	 * @throws ParseException when a parse exception occurs
	 */
	T parse(String formatted, Locale locale) throws ParseException;
}

Note ParseException is java.text.ParseException and is checked.


Affects: 2.5.6

Referenced from: commits 2381452

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions