Java Reference
In-Depth Information
Browser
request
name=value
String
"value"
TypeConverter<T>
T
setName(T)
ActionBean
Figure 5.1: Type conversion
public interface
TypeConverter<T> {
void
setLocale(Locale locale);
T convert(String input, Class<?
extends
T> targetType,
Collection<ValidationError> errors);
}
Stripes gives type converters the user's locale so that the type con-
version can be done in a locale-sensitive manner, if necessary. Then,
Stripes calls the
convert
( ) method with the
String
input parameter from
the request, the action bean property type, and a list of validation
errors. If the type conversion fails, the converter adds an error mes-
sage to the list and returns
null
. If all goes well, the method returns the
value converted to the
T
type, and Stripes sets the action bean property
with this value.
Out of the box, Stripes automatically uses built-in type converters for
basic data types:
•
byte
,
Byte
,
short
,
Short
,
int
,
Integer
,
long
,
Long
,
java.math.BigInteger
•
float
,
Float
,
double
,
Double
,
java.math.BigDecimal
•
java.util.Date
•
boolean
,
Boolean
•
char
,
Character
•
enum
Search WWH ::
Custom Search