net.sourceforge.stripes.format
Class EnumFormatter

java.lang.Object
  extended by net.sourceforge.stripes.format.EnumFormatter
All Implemented Interfaces:
Formatter<Enum<?>>

public class EnumFormatter
extends Object
implements Formatter<Enum<?>>

A simple formatter for Enum classes that always returns the value of Enum.name(). Intended really only to enable the seamless usage of enums as values in hidden fields, radio buttons, checkboxes etc. it is not intended that this will be used to format Enum values into text fields where a localized value might be more appropriate.

Since:
Stripes 1.4.1
Author:
Tim Fennell

Constructor Summary
EnumFormatter()
           
 
Method Summary
 String format(Enum<?> input)
          Formats the supplied value as a String.
 void init()
          Does nothing since no initialization is needed.
 void setFormatPattern(String formatPattern)
          Does nothing.
 void setFormatType(String formatType)
          Does nothing.
 void setLocale(Locale locale)
          Does nothing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EnumFormatter

public EnumFormatter()
Method Detail

setFormatType

public void setFormatType(String formatType)
Does nothing. Format types are not supported for Enums.

Specified by:
setFormatType in interface Formatter<Enum<?>>

setFormatPattern

public void setFormatPattern(String formatPattern)
Does nothing. Format patterns are not supported for Enums.

Specified by:
setFormatPattern in interface Formatter<Enum<?>>

setLocale

public void setLocale(Locale locale)
Does nothing. Enums values are always formatted using name() which is not localizable.

Specified by:
setLocale in interface Formatter<Enum<?>>

init

public void init()
Does nothing since no initialization is needed.

Specified by:
init in interface Formatter<Enum<?>>

format

public String format(Enum<?> input)
Formats the supplied value as a String. If the value cannot be formatted because it is an inappropriate type, or because faulty pattern information was supplied, should fail loudly by throwing a RuntimeException or subclass thereof.

Specified by:
format in interface Formatter<Enum<?>>
Parameters:
input - an object of a type that the formatter knows how to format
Returns:
a String version of the input, formatted for the chosen locale


? Copyright 2005-2006, Stripes Development Team.