Table 6-1.BeanWrapper Default PropertyEditors
PropertyEditor Result Description
ByteArrayPropertyEditor byte[] String to a byte[] with
getBytes().
ClassEditor Class Similar to Class.forName().
FileEditor java.io.File Via new File(pathname).
InputStreamEditor java.io.InputStream See also ResourceEditor.
LocaleEditor java.util.Locale See also Locale’s toString()
method for format.
PropertiesEditor java.util.Properties See format in
java.util.Properties.
ResourceArrayPropertyEditor Resource[] Wildcard resource locations,
e.g. file:c:\my*.txt.
StringArrayPropertyEditor String[] Comma-separated Stringto
Stringarray.
URLEditor java.net.URL Fully qualified standard URL
or Spring’s classpath:prefix
URL.
CustomCollectionEditor java.util.Collectionsubclass Converts one collection type
to another. It will convert a
Stringto a single element
collection. It does not
convert the collection to a
String.
CharacterEditor charor Character Single character Stringto
Character.
CustomBooleanEditor booleanor Boolean true/on/yes/1 for true, and
false/off/no/0 for false.
CustomNumberEditor Primitive number or Number Can use a NumberFormatfor
wrapper, BigDecimalor Locale-specific formatting or
BigInteger default to valueOf()and
toString().
Spring provides a few more PropertyEditors, such as the CustomDateEditor, which require
manual registration and configuration, and it is simple to create others specific to your needs.
PropertyEditors are applied intelligently to the data binding process. You begin by declar-
ing any PropertyEditors not already in the default set, and the DataBinder’s process will
automatically apply them when it encounters a property not of type String.
For example, to begin, let us create a simple command bean with properties other than
String. We will first create a bean (Listing 6-22) with properties that the DataBinderalready
knows about. Then we will declare a CustomDateEditor(a custom PropertyEditorprovided by
Spring) to handle java.util.Dateobjects. Last, we will create our own PropertyEditorto han-
dle a specific internal domain class.
136 CHAPTER 6 ■THE CONTROLLER MENAGERIE