Hello everyone,
I've recently written the following PropertyEditor for JDK 1.5 style
Enums. I think that could be a good addition to Spring >= 1.2. So, feel
free to include it if it fits (should I open an issue for this?)
public class EnumEditor extends PropertyEditorSupport
{
private Class enumClass;
private boolean strictCase;
public EnumEditor(Class enumClass, boolean strictCase)
{
this.enumClass = enumClass;
this.strictCase = strictCase;
}
public void setAsText(String text) throws IllegalArgumentException
{
if(strictCase)
text = text.toUpperCase();
setValue(Enum.valueOf(enumClass, text));
}
public String getAsText()
{
String text = ((Enum) getValue()).name();
if(strictCase)
return text.toLowerCase();
else
return text;
}
}
The strictCase option is for conversion between uppercase Enum instances
(like constants) and usually lowercase identifiers used in web forms.
Regards,
Andreas
|