|
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.ShowDateTime
public final class ShowDateTime
Custom tag to display a DateTime
in a particular format.
This class uses:
LocaleSource
to determine the Locale 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, with the default format defined by DateConverter
:
<w:showDateTime/>
Display a specific date object, present in any scope :
<w:showDateTime name="dateOfBirth"/>
Display a date returned by some object in scope :
<c:set value="${visit.lunchDate}" var="lunchDate"/>
<w:showDateTime name="lunchDate"/>
Display with a non-default date format :
<w:showDateTime name="lunchDate" pattern="YYYY-MM-DD"/>
Display with a non-default date format sensitive to Locale
:
<w:showDateTime name="lunchDate" patternKey="next.visit.lunch.date"/>
Suppress the display of midnight, using a pipe-separated list of 'midnights' :
<w:showDateTime name="lunchDate" suppressMidnight="12:00 AM|00 h 00"/>
Constructor Summary | |
---|---|
ShowDateTime()
|
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 DateTime object already present in some scope. |
void |
setPattern(String aFormat)
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. |
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 ShowDateTime()
Method Detail |
---|
public void setName(String aName)
DateTime
object already present in some scope.
Searches from narrow to wide scope to find the corresponding object.
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 aFormat)
Setting this attribute will override the default format used by
DateConverter
.
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.
aFormat
- has content, and is a date format suitable for the format .
methods of DateTime
.public void setPatternKey(String aFormatKey)
Locale
.
Setting this attribute will override the default format used by
DateConverter
.
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' (for a Date) or YYYY-MM-DD (for a DateTime
).
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 format suitable for the format methods of DateTime
.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 |