Java Reference
In-Depth Information
You can also use a DecimalFormat -compatible format pattern, such as
"#,##0.0" to produce "2,468.2" .
Enumerated Types
Stripes also has a formatter for enumerated types, EnumFormatter , which
simply uses Enum.name ( ) to return a result. This is always the name of
the enum constant—the locale, format type, and format pattern are not
used by this formatter.
Objects
Finally, when Stripes has no specific formatter for a type T , the fallback
is to just call the toString ( ) method. This way, formatting always pro-
duces a String even if Stripes doesn't know anything about the type T ,
because toString ( ) is defined on Object , the parent of all Java classes.
Using Formatters
The Stripes tags that accept the formatType= and formatPattern= attri-
butes, such as <s:format> and <s:text>, use formatters to display val-
ues. Both formatType= and formatPattern= are optional attributes, so for-
matters either have a default value or do not use these attributes. Let's
look at an example of using a formatter.
In the contact form of the webmail application, the user can enter the
contact's birth date. This date is displayed in the contact view and also
redisplayed in the form when updating an existing contact.
Without formatting, a birth date entered by the user as 1982-08-30 is
displayed in the contact view as Mon Aug 30 00:00:00 EDT 1982 and in the
contact form's text field as 8/30/82 .
Let's use the date formatter to display the contact birth date in the yyyy-
MM-dd format, both in the contact view and in the contact form. In the
contact view, we can do this with the <s:format> tag:
Download email_07/web/WEB-INF/jsp/contact_view.jsp
<td class="label"> Birth date: </td>
<td class="value">
<s:format value="${actionBean.contact.birthDate}"
formatPattern="yyyy-MM-dd"/>
</td>
 
 
Search WWH ::




Custom Search