Java Reference
In-Depth Information
Single Characters
Last (and perhaps least) of the built-in type converters is the character
type converter. It just takes the first character in the input
String
to
produce a
char
or a
Character
. So,
"Hello"
will be converted to
'H'
.
Other Provided Type Converters
The type converters we've seen so far are used automatically. Stripes
also provides a few other type converters that do the conversion only if
we specifically tell Stripes to use them. These additional type converters
are as follows:
•
EmailTypeConverter
•
CreditCardTypeConverter
•
PercentageTypeConverter
•
OneToManyTypeConverter
To indicate we want one of these type converters to convert the input
for a given property, we annotate the property with
@Validate(converter=
TheTypeConverter.class)
. For example:
// Use EmailTypeConverter for this property
@Validate(converter=EmailTypeConverter.
class
)
public
String email;
TypeConverter
.
PercentageTypeConverter
PercentageTypeConverter
works on a property of decimal type:
float
,
Float
,
double
,
Double
, or
BigDecimal
. The input string is considered as a per-
centage, with or without a percent symbol (%). The numerical result is
the value of the input divided by
100
.
PercentageTypeConverter
preprocesses the input just like the other deci-
mal type converters. For example, it accepts all these inputs to produce
the corresponding results, as we can see in the table on the next page.
Search WWH ::
Custom Search