|
Version 4.10.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Object SimpleTagSupport hirondelle.web4j.ui.tag.TagHelper hirondelle.web4j.ui.tag.ShowDate
public final class ShowDate
Display a Date
in a particular format.
This class uses:
LocaleSource
to determine the Locale associated with the current request
TimeZoneSource
for the time zone associated with the current request
DateConverter
to format the given date
Translator
for localizing the argument passed to setPatternKey(java.lang.String)
.
Display the current system date :
<w:showDate/>
Display a specific Date object, present in any scope :
<w:showDate name="dateOfBirth"/>
Display a date returned by some object in scope :
<c:set value="${visit.lunchDate}" var="lunchDate"/>
<w:showDate name="lunchDate"/>
Display with a non-default date format :
<w:showDate name="lunchDate" pattern="E, MMM dd"/>
Display with a non-default date format sensitive to Locale
:
<w:showDate name="lunchDate" patternKey="next.visit.lunch.date"/>
Display in a specific time zone :
<w:showDate name="lunchDate" timeZone="America/Montreal"/>
Suppress the display of midnight, using a pipe-separated list of 'midnights' :
<w:showDate name="lunchDate" suppressMidnight="12:00 AM|00 h 00"/>
Constructor Summary | |
---|---|
ShowDate()
|
Method Summary | |
---|---|
protected void |
crossCheckAttributes()
Perform validations that apply to more than one attribute. |
protected String |
getEmittedText(String aOriginalBody)
Return the text this tag will display in the resulting web page. |
void |
setName(String aName)
Optionally set the name of a Date object already present in some scope. |
void |
setPattern(String aDateFormat)
Optionally set the format for rendering the date. |
void |
setPatternKey(String aFormatKey)
Optionally set the format for rendering the date according to Locale . |
void |
setSuppressMidnight(String aMidnightStyles)
Optionally suppress the display of midnight. |
void |
setTimeZone(String aCustomTimeZone)
Optionally set the TimeZone for formatting the date. |
Methods inherited from class hirondelle.web4j.ui.tag.TagHelper |
---|
checkForContent, doTag, getPageContext, getPageName, getRequest, getResponse |
Methods inherited from class SimpleTagSupport |
---|
findAncestorWithClass, getJspBody, getJspContext, getParent, setJspBody, setJspContext, setParent |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ShowDate()
Method Detail |
---|
public void setName(String aName)
Date
object already present in some scope.
Searches from narrow to wide scope to find the corresponding Date.
If this method is called and no corresponding object can be found using the given name, then this tag will emit an empty String.
If this method is not called at all, then the current system date is used, as
defined by the configured TimeSource
.
aName
- must have content.public void setPattern(String aDateFormat)
Setting this attribute will override the default format of
DateConverter.formatEyeFriendly(Date, Locale, TimeZone)
.
Calling this method is suitable only when
the date format does not depend on Locale
. Otherwise,
setPatternKey(String)
must be used instead.
Only one of setPattern(String)
and setPatternKey(String)
can be called at a time.
aDateFormat
- has content, and is in the form expected by
SimpleDateFormat
.public void setPatternKey(String aFormatKey)
Locale
.
Setting this attribute will override the default format of
DateConverter.formatEyeFriendly(Date, Locale, TimeZone)
.
This method uses a Translator
to look up the "real"
date pattern to be used, according to the Locale
returned
by LocaleSource
.
For example, if the value 'format.next.lunch.date' is passed to
this method, then that value is passed to a Translator
, which will return
a pattern specific to the Locale
attached to this request, such as
'EEE, dd MMM'.
Only one of setPattern(String)
and setPatternKey(String)
can be called at a time.
aFormatKey
- has content, and, when passed to Translator
, will
return a date pattern in the form expected by SimpleDateFormat
.public void setTimeZone(String aCustomTimeZone)
TimeZone
for formatting the date.
If this attribute is not set, then TimeZoneSource
is used.
aCustomTimeZone
- in the style expected by TimeZone.getTimeZone(java.lang.String)
.
If the format is not in the expected style, then UTC is used (same as Greenwich Mean Time).public void setSuppressMidnight(String aMidnightStyles)
For example, set this attribute to '00:00:00' to force '1999-12-31 00:00:00' to display as 1999-12-31, without the time.
If this attribute is set, and if any of the aMidnightStyles is found anywhere in the formatted date, then the formatted date is truncated, starting from the given midnight style. That is, all text appearing after the midnight style is removed, including any time zone information. (Then the result is trimmed.)
aMidnightStyles
- is pipe-separated list of Strings which denote the possible forms of
midnight. Example value : '00:00|00 h 00'.protected void crossCheckAttributes()
TagHelper
This default implementation does nothing.
Validations that apply to a single attribute should be performed in its corresponding setXXX method.
If a problem is detected, subclasses must emit a RuntimeException describing the problem. If all validations apply to only to a single attribute, then this method should not be overridden.
crossCheckAttributes
in class TagHelper
protected String getEmittedText(String aOriginalBody)
TagHelper
getEmittedText
in class TagHelper
aOriginalBody
- is the evaluated body of this tag. If there is no body, or
if the body is present but empty, then it is null.
|
Version 4.10.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |