Project Documentation

Summary

Tag name: <tr:convertDateTime>

type: org.apache.myfaces.trinidad.DateTime
Converts string into java.util.Date and vice versa based on the pattern and style set.

The default dateStyle is shortish. Shortish is identical to short but forces the year to be a full four digits. dateStyle defaults to shortish if it was not set.

Timezone can be set per web-app in trinidad-config.xml configuration file. If timeZone is not set on the converter, then timezone will be defaulted to the value set in trinidad-config.xml configuration file. If it is not set in the configuration file, then it will be defaulted to GMT.

The converter always allows a level of leniency while converting user input value to date to the following extent.

  • A converter with associated pattern 'MMM' for month, when attached to any value holder, will accept values with month specified in the form 'MM' or 'M' as valid.
  • Allows use of separators '-' or '.' or '/' irrespective of the separator specified in the associated pattern.
  • The leniency is applicable to both 'pattern' and 'secondaryPattern'.

For example:
When pattern on the converter is set to "MMM/d/yyyy" the following inputs are tolerated as valid by the converter.

Jan/4/2004
Jan-4-2004
Jan.4.2004
01/4/2004
01-4-2004
01.4.2004
1/4/2004
1-4-2004
1.4.2004

This converter is automatically registered under the standard converter ID, and therefore will be used when the <f:convertDateTime> tag is used.

Code Example(s)

<tr:inputText id="mdf5" value="2004/09/06"
                        label="Date">
  <tr:convertDateTime pattern="yyyy/M/d"  secondaryPattern="d/M/yyyy" />
</tr:inputText>

Attributes

Name Type Supports EL? Description
dateStyleStringYes Default Value: shortish

Predefined formatting style which determines how the date component of a date string is to be formatted and parsed. Applied only if type is "date" or "both". Valid values are "shortish", "short", "default", "medium", "long", and "full". Default value is "shortish".
disabledbooleanYes Default Value: false

Whether the converter should be disabled, default to false.
localejava.util.LocaleYes Locale whose predefined styles for dates and times are used during formatting or parsing. If not specified or if null, the Locale returned by FacesContext.getViewRoot().getLocale() will be used.
messageDetailConvertBothStringYes

Custom error message to be used, for creating detail part of faces message, for date-time based value that cannot be converted to date when type is set to 'both' and pattern is not set or is null.

Parameters:

  • {0} the label that identifies the component
  • {1} value entered by the user
  • {2} an example of the format the converter is expecting
messageDetailConvertDateStringYes

Custom error message to be used, for creating detail part of faces message, for values that cannot be converted to date when the pattern / secondary pattern is set or when type is set to 'date' and pattern is not set or is null.

Parameters:

  • {0} the label that identifies the component
  • {1} value entered by the user
  • {2} an example of the format the converter is expecting
messageDetailConvertTimeStringYes

Custom error message to be used, for creating detail part of faces message, for time based value that cannot be converted to date when type is set to 'time', pattern is not set or is null

Parameters:

  • {0} the label that identifies the component
  • {1} value entered by the user
  • {2} an example of the format the converter is expecting
patternStringYes Custom formatting pattern which determines how the date/time string should be formatted and parsed.
secondaryPatternStringYes Second pattern, which will be used as a second attempt to parse a string if the primary pattern or styles fail, but is never used for formatting strings.
timeStyleStringYes Default Value: short

Predefined formatting style which determines how the time component of a date string is to be formatted and parsed. Applied only if type is "time" or "both". Valid values are "default", "short", "medium", "long", and "full". Default value is "short".
timeZonejava.util.TimeZoneYes Time zone in which to interpret any time information in the date string. If not set here, picks this value from trinidad-config.xml configuration file. If not defined there, then it is defaulted to the value returned by TimeZone.getDefault() which is usually the server JVM timezone.
typeStringYes Default Value: date

Specifies what contents the string value will be formatted to include, or parsed. Valid values are "date", "time", and "both". Default value is "date".