Version 4.10.0

hirondelle.web4j.ui.tag
Class ShowDate

Object
  extended by SimpleTagSupport
      extended by hirondelle.web4j.ui.tag.TagHelper
          extended by hirondelle.web4j.ui.tag.ShowDate
All Implemented Interfaces:
JspTag, SimpleTag

public final class ShowDate
extends TagHelper

Display a Date in a particular format.

This class uses:

Examples

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

ShowDate

public ShowDate()
Method Detail

setName

public void setName(String aName)
Optionally set the name of a 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.

Parameters:
aName - must have content.

setPattern

public void setPattern(String aDateFormat)
Optionally set the format for rendering the date.

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.

Parameters:
aDateFormat - has content, and is in the form expected by SimpleDateFormat.

setPatternKey

public void setPatternKey(String aFormatKey)
Optionally set the format for rendering the date according to 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.

Parameters:
aFormatKey - has content, and, when passed to Translator, will return a date pattern in the form expected by SimpleDateFormat.

setTimeZone

public void setTimeZone(String aCustomTimeZone)
Optionally set the TimeZone for formatting the date.

If this attribute is not set, then TimeZoneSource is used.

Parameters:
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).

setSuppressMidnight

public void setSuppressMidnight(String aMidnightStyles)
Optionally suppress the display of midnight.

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.)

Parameters:
aMidnightStyles - is pipe-separated list of Strings which denote the possible forms of midnight. Example value : '00:00|00 h 00'.

crossCheckAttributes

protected void crossCheckAttributes()
Description copied from class: TagHelper
Perform validations that apply to more than one attribute.

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.

Overrides:
crossCheckAttributes in class TagHelper

getEmittedText

protected String getEmittedText(String aOriginalBody)
Description copied from class: TagHelper
Return the text this tag will display in the resulting web page.

Specified by:
getEmittedText in class TagHelper
Parameters:
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.
Returns:
the text to display in the resulting web page.

Version 4.10.0

Copyright Hirondelle Systems. Published October 19, 2013 - User Guide - All Docs.