Java Reference
In-Depth Information
Chapter 5
There's More to Life Than Strings:
Working with Data Types
When a client submits an HTTP request, all parameters are limited to
the String type. We certainly don't want our action bean properties to
suffer from this limitation; we want properties that can be of any type.
When request parameters are bound to action bean properties, some
work has to be done to convert the String parameter to the property's
data type. This is what Stripes calls type conversion.
Going the other way, the information that action beans provide are of
any data type but must be converted to a String to be displayed to the
client. Stripes refers to this as formatting.
When developing applications, we want to use the data types that are
best suited to our business model. We also want to let our users express
their input in a format that is most natural to them. With type conver-
sion and formatting, we can bridge the gap between these two require-
ments. Stripes makes it easy to work with any data type, including
adding support for our own custom types.
5.1
Type Conversion Concepts
Look at Figure 5.1 , on the next page. When the name=value request
parameter is bound to the name property of type T in the action bean,
Stripes needs to know how to convert "value" from String to T . This is
where a type converter is used. A type converter is simply an imple-
mentation of the TypeConverter<T> interface:
 
 
 
 
Search WWH ::




Custom Search