Parent Project
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
dateStyle String Yes 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".
disabled boolean Yes Default Value: false

Whether the converter should be disabled, default to false.
locale java.util.Locale Yes 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.
messageDetailConvertBoth String Yes

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
messageDetailConvertDate String Yes

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
messageDetailConvertTime String Yes

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
pattern String Yes Custom formatting pattern which determines how the date/time string should be formatted and parsed.
secondaryPattern String Yes 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.
timeStyle String Yes 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".
timeZone java.util.TimeZone Yes 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.
type String Yes 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".