|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.click.util.Format
Provides the default object for formatting the display of model objects in Velocity templates and JSP pages.
For Velocity templates a Format object is added to the Velocity Context using the name "format", while for JSP pages an instance is added as a request attribute using the same key. For example the following Page code adds a date to the model:public void onGet() { Date date = order.deliveryDate(); addModel("deliveryDate", date); }In the page template we use the format object:
Delivery date: $format.date($deliveryDate, "dd MMM yyyy")Which renders the output as:
Delivery date: 21 Jan 2004 |
<format classname="com.mycorp.utils.MyFormat"/>
After a Page is created its format property
is set.
The ClickServlet will then add this property to the Velocity Context.
When subclassing Format ensure it is light weight object, as a new format
object will be created for every new Page.
PageImports
,
Serialized FormField Summary | |
protected String |
emptyString
The empty string value. |
protected Locale |
locale
The request context locale. |
Constructor Summary | |
Format()
|
Method Summary | |
String |
currency(Number number)
Return a currency formatted String value for the given number, using the default Locale. |
String |
currentDate()
Return a formatted current date string using the default DateFormat. |
String |
currentDate(String pattern)
Return a formatted current date string using the given formatting pattern. |
String |
date(Date date)
Return a formatted date string using the given date and the default DateFormat. |
String |
date(Date date,
String pattern)
Return a formatted date string using the given date and formatting pattern. |
String |
decimal(Number number)
Return a decimal formatted string using the given number and pattern. |
String |
decimal(Number number,
String pattern)
Return a decimal formatted string using the given number and pattern. |
String |
email(String email)
Return an email hyperlink using the given email address. |
String |
email(String email,
String attribute)
Return an email hyperlink using the given email address. |
String |
getEmptyString()
Returns the format empty string value: "". |
Locale |
getLocale()
Return the locale used to format objects. |
String |
html(Object value)
Escape the given object value as a HTML string. |
String |
javascript(String value)
Escape the given object value as a JavaScript string, or "" if the object is null. |
String |
limitLength(String value,
int maxlength)
Return the value string limited to maxlength characters. |
String |
limitLength(String value,
int maxlength,
String suffix)
Return the value string limited to maxlength characters. |
String |
link(String value)
Return an hyperlink using the given URL or email address value. |
String |
link(String value,
String attribute)
Return an hyperlink using the given URL or email address value. |
String |
message(String pattern,
List arguments)
Return a formatted string using the given message pattern and arguments. |
String |
message(String pattern,
Object argument)
Return a formatted string using the given message pattern and argument. |
String |
message(String pattern,
Object[] arguments)
Return a formatted string using the given message pattern and arguments. |
String |
percentage(Number number)
Return a percentage formatted number string using number. |
void |
setEmptyString(String value)
Set the format empty string value. |
String |
string(Object object)
Return the string representation of the given object. |
String |
time(Date date)
Return a formatted time string using the given date and the default DateFormat. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected Locale locale
protected String emptyString
Constructor Detail |
public Format()
Method Detail |
public Locale getLocale()
public String getEmptyString()
public void setEmptyString(String value)
value
- the format empty string valuepublic String currency(Number number)
getEmptyString()
value.
number
- the number to format
public String currentDate()
public String currentDate(String pattern)
pattern
- the SimpleDateFormat formatting pattern
IllegalArgumentException
- if the pattern string is nullpublic String date(Date date, String pattern)
getEmptyString()
value.
Letter | Date or Time Component | Presentation | Examples |
---|---|---|---|
G
| Era designator | Text | AD
|
y
| Year | Year | 1996 ; 96
|
M
| Month in year | Month | July ; Jul ; 07
|
w
| Week in year | Number | 27
|
W
| Week in month | Number | 2
|
D
| Day in year | Number | 189
|
d
| Day in month | Number | 10
|
F
| Day of week in month | Number | 2
|
E
| Day in week | Text | Tuesday ; Tue
|
a
| Am/pm marker | Text | PM
|
H
| Hour in day (0-23) | Number | 0
|
k
| Hour in day (1-24) | Number | 24
|
K
| Hour in am/pm (0-11) | Number | 0
|
h
| Hour in am/pm (1-12) | Number | 12
|
m
| Minute in hour | Number | 30
|
s
| Second in minute | Number | 55
|
S
| Millisecond | Number | 978
|
z
| Time zone | General time zone | Pacific Standard Time ; PST ; GMT-08:00
|
Z
| Time zone | RFC 822 time zone | -0800
|
date
- the date value to formatpattern
- the SimpleDateFormat formatting pattern
IllegalArgumentException
- if the pattern string is nullpublic String date(Date date)
getEmptyString()
value.
date
- the date value to format
public String decimal(Number number, String pattern)
getEmptyString()
value.
Please Note: Velocity will not correctly parse the '#' decimal
number pattern character and will throw a parsing exception. When using
this method substitute the '#' decimal pattern character
(Digit, zero shows as absent) with 'N'. Internally this method will
reverse the subsitution before invoking DecimalFormat.
For example:
$format.decimal($value, "N,NN0.00") -> "#,##0.00"
Symbol | Location | Localized? | Meaning |
---|---|---|---|
0
| Number | Yes | Digit |
#
| Number | Yes | Digit, zero shows as absent |
.
| Number | Yes | Decimal separator or monetary decimal separator |
-
| Number | Yes | Minus sign |
,
| Number | Yes | Grouping separator |
E
| Number | Yes | Separates mantissa and exponent in scientific notation. Need not be quoted in prefix or suffix. |
;
| Subpattern boundary | Yes | Separates positive and negative subpatterns |
%
| Prefix or suffix | Yes | Multiply by 100 and show as percentage |
\u2030
| Prefix or suffix | Yes | Multiply by 1000 and show as per mille |
¤ (\u00A4 )
| Prefix or suffix | No | Currency sign, replaced by currency symbol. If doubled, replaced by international currency symbol. If present in a pattern, the monetary decimal separator is used instead of the decimal separator. |
'
| Prefix or suffix | No | Used to quote special characters in a prefix or suffix,
for example, "'#'#" formats 123 to
"#123" . To create a single quote
itself, use two in a row: "# o''clock" .
|
number
- the number to formatpattern
- the decimal format pattern
IllegalArgumentException
- if the pattern string is nullpublic String decimal(Number number)
getEmptyString()
value.
number
- the number to format
public String email(String email)
getEmptyString()
value
will rendered instead.
The format of the returned email string will be:
<a href='mailto:email'>email</a>
email
- the email address to hyperlink
public String email(String email, String attribute)
getEmptyString()
value
will rendered instead.
The format of the returned email string will be:
<a href='mailto:email' attribute>email</a>
email
- the email address to hyperlinkattribute
- the anchor tag attribute to render
public String html(Object value)
getEmptyString()
value.
value
- unescaped HTML
public String javascript(String value)
Implementation is provided by Jakarta Commons Lang utility: StringEscapeUtils.escapeJavaScript(String)
value
- unescaped JavaScript
public String limitLength(String value, int maxlength)
value
- the string value to limit the length ofmaxlength
- the maximum string length
public String limitLength(String value, int maxlength, String suffix)
value
- the string value to limit the length ofmaxlength
- the maximum string lengthsuffix
- the suffix to append to the length limited string
public String link(String value)
getEmptyString()
value
will rendered instead.
value
- the URL or email address to hyperlink
public String link(String value, String attribute)
getEmptyString()
value
will rendered instead.
value
- the URL or email address to hyperlinkattribute
- the anchor tag attribute to render
public String message(String pattern, Object argument)
MessageFormat
for information on the message
pattern string.
pattern
- the message patternargument
- the message argument
public String message(String pattern, Object[] arguments)
MessageFormat
for information on the message
pattern string.
pattern
- the message patternarguments
- the message arguments
public String message(String pattern, List arguments)
MessageFormat
for information on the message
pattern string.
pattern
- the message patternarguments
- list of message arguments
public String percentage(Number number)
getEmptyString()
value.
number
- the number value to format
public String time(Date date)
getEmptyString()
value.
date
- the date value to format
public String string(Object object)
getEmptyString()
value.
object
- the object to format
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |