{@link Converter} implementation for java.util.Date
values. Converts an strings to and from java.util.Date objects.
The converter has additonal features than standard JSF {@link javax.faces.convert.DateTimeConverter}. New dateStyle
shortish
has been introduced. Shortish is identical to
short
but forces the year to be a full four digits. If dateStyle is not set, then
dateStyle
defaults to
shortish
.
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
The detail part of faces message,for conversion errors can be customized by overriding the message associated with each CONVERT_[TYPE]_MESSAGE_ID.
The methods used for customizing the detail message associated with each id is given below:
- {@link #CONVERT_DATE_MESSAGE_ID} - {@link #setMessageDetailConvertDate(String)}
- {@link #CONVERT_TIME_MESSAGE_ID} - {@link #setMessageDetailConvertTime(String) }
- {@link #CONVERT_BOTH_MESSAGE_ID} - {@link #setMessageDetailConvertBoth(String) }
The custom messages can contain placeholders, which will be replaced with values as specified in its corresponding message id.
The getAsObject()
method parses a String into a java.util.Date
, according to the following algorithm:
- If the specified String is null, return a
null
. Otherwise, trim leading and trailing whitespace before proceeding. - If the specified String - after trimming - has a zero length, return
null
. - If the
locale
property is not null, use that Locale
for managing parsing. Otherwise, use the Locale
from the UIViewRoot
. - If a
pattern
has been specified, its syntax must conform the rules specified by java.text.SimpleDateFormat
. Such a pattern will be used to parse, and the type
, dateStyle
, and timeStyle
properties will be ignored. - If a
pattern
has not been specified, parsing will be based on the type
property, which expects a date value, a time value, or both. Any date and time values included will be parsed in accordance to the styles specified by dateStyle
and timeStyle
, respectively. - If conversion fails with
pattern
or style
and if secondaryPattern
is set, re parsers based on the secondaryPattern
. Syntax for secondaryPattern
must conform to the rules specified by java.text.SimpleDateFormat
. - Parsing is lenient as outlined earlier and is not the same as setting leniency on
java.text.DateFormat
The getAsString()
method expects a value of type java.util.Date
(or a subclass), and creates a formatted String according to the following algorithm:
- If the specified value is null, return a zero-length String.
- If the specified value is a String, return it unmodified.
- If the
locale
property is not null, use that Locale
for managing formatting. Otherwise, use the Locale
from the UIViewRoot
. - If a
pattern
has been specified, its syntax must conform the rules specified by java.text.SimpleDateFormat
. Such a pattern will be used to format, and the type
, dateStyle
, and timeStyle
properties will be ignored. - If a
pattern
has not been specified, formatting will be based on the type
property, which includes a date value, a time value, or both into the formatted String. Any date and time values included will be formatted in accordance to the styles specified by dateStyle
and timeStyle
, respectively. secondaryPattern
even if set is never used for formatting to a String
@see #CONVERT_DATE_MESSAGE_ID
@see #CONVERT_TIME_MESSAGE_ID
@see #CONVERT_BOTH_MESSAGE_ID
@see java.text.DateFormat
@see java.text.SimpleDateFormat
@version $Name: $ ($Revision: adfrt/faces/adf-faces-api/src/main/java/oracle/adf/view/faces/convert/DateTimeConverter.java#0 $) $Date: 10-nov-2005.19:09:11 $