Java Reference
In-Depth Information
The date is displayed in the contact form using the same formatPattern=
in the <s:text> tag:
Download email_07/web/WEB-INF/jsp/contact_form.jsp
<td> Birth date: </td>
<td>
<s:text name="contact.birthDate"
formatPattern="yyyy-MM-dd"/>
</td>
The birth date is now displayed in a consistent format.
We can still let the user enter the birth date using the default pat-
terns accepted by the date type converter. If we wanted to enforce the
Year-Month-Day pattern for user input, we'd just add one line to the
StripesResource.properties file:
Download email_07/res/StripesResources.properties
stripes.dateTypeConverter.formatStrings=yyyy M d
That's all well and good for built-in type conversion and formatting, but
what about using our own data types? That's coming up next, after this
word from your local station. (That's your cue to get up, stretch, and go
grab something from the refrigerator.)
5.4
Working with Custom Data Types
The Stripes type conversion and formatting mechanisms make it easy to
add support for custom data types. Let's see how this works by adding a
PhoneNumber data type in the contact information of the webmail appli-
cation.
Implementing a Type Converter
The contact form supports many variations of input for the contact's
phone number. The value is stored in a String exactly as entered by the
user. We might end up with values such as 654-456-4567 , (654) 567-5678 ,
654 234.2345 , and so on. It'd be nice to continue accepting these different
input formats but store the value in the model in a format-independent
way. A phone number has an area code, a prefix, and a suffix. We can
use a simple PhoneNumber class.
 
 
 
Search WWH ::




Custom Search