|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavax.faces.convert.DateTimeConverter
org.apache.myfaces.trinidad.convert.DateTimeConverter
public class DateTimeConverter
Converter implementation for java.util.Date
values. Converts an strings to and from java.util.Date objects.
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.
For example: When pattern on the converter is set to "MMM/d/yyyy" the following inputs are tolerated as valid by the converter.
The methods used for customizing the detail message associated with each id is given below:
CONVERT_DATE_MESSAGE_ID - setMessageDetailConvertDate(String)CONVERT_TIME_MESSAGE_ID - setMessageDetailConvertTime(String)CONVERT_BOTH_MESSAGE_ID - setMessageDetailConvertBoth(String)The getAsObject() method parses a String into a
java.util.Date, according to the following algorithm:
null. Otherwise, trim leading and trailing
whitespace before proceeding.null.locale property is not null,
use that Locale for managing parsing. Otherwise, use the
Locale from the UIViewRoot.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.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.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.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:
locale property is not null,
use that Locale for managing formatting. Otherwise, use the
Locale from the UIViewRoot.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.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
CONVERT_DATE_MESSAGE_ID,
CONVERT_TIME_MESSAGE_ID,
CONVERT_BOTH_MESSAGE_ID,
DateFormat,
SimpleDateFormat| Field Summary | |
|---|---|
static java.lang.String |
CONVERT_BOTH_MESSAGE_ID
The message identifier of the FacesMessage to be created if the value cannot be converted to a date when type
is set to 'both' and pattern is either null or not set. |
static java.lang.String |
CONVERT_DATE_MESSAGE_ID
The message identifier of the FacesMessage to be created if the value cannot be converted to a date, when pattern
is null or not set and type is set to 'date'. |
static java.lang.String |
CONVERT_TIME_MESSAGE_ID
The message identifier of the FacesMessage to be created if the value cannot be converted date time object, when type
is set to 'time' and pattern is null or not set. |
static java.lang.String |
CONVERTER_ID
Standard converter id for this converter. |
| Constructor Summary | |
|---|---|
DateTimeConverter()
Creates a DateTimeConverter |
|
DateTimeConverter(java.lang.String pattern)
Creates a DateTimeConverter with the specified SimpleDateFormat format pattern |
|
DateTimeConverter(java.lang.String pattern,
java.lang.String secondaryPattern)
Creates a DateTimeConverter with the specified SimpleDateFormat format pattern and a secondary pattern. |
|
| Method Summary | |
|---|---|
boolean |
equals(java.lang.Object object)
Compares this DateTimeConverter with the specified Object for equality. |
java.lang.Object |
getAsObject(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component,
java.lang.String value)
Convert the specified string value, which is associated with the specified UIComponent, into a java.util.Date object
based on the values set. |
java.lang.String |
getAsString(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component,
java.lang.Object value)
Convert the model Date object value, into a String based on the pattern or styles. |
protected java.util.Date |
getDate(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component)
Gets the existing date from the component. |
protected java.text.DateFormat |
getDateFormat(javax.faces.context.FacesContext context,
java.lang.String pattern,
boolean forParsing)
|
java.lang.String |
getDateStyle()
Return the style to be used to format or parse dates. |
protected java.lang.String |
getExample(javax.faces.context.FacesContext context)
|
protected java.util.TimeZone |
getFormattingTimeZone(java.util.TimeZone tZone)
Returns the TimeZone that will be set on DateFormat for formatting and parsing the dates. |
java.lang.String |
getHintBoth()
Return custom hintBoth message. |
java.lang.String |
getHintDate()
Return custom hintDate message. |
java.lang.String |
getHintTime()
Return custom hintTime message. |
java.util.Locale |
getLocale()
Return the Locale that was set. |
java.lang.String |
getMessageDetailConvertBoth()
Return custom detail error message that was set for creating FacesMessage,
for values that cannot be converted to Date
when type is set to 'both'. |
java.lang.String |
getMessageDetailConvertDate()
Return custom detail error message that was set for creating FacesMessage,
for values that cannot be converted to Date when
pattern / secondary pattern is set or
when type is set to 'date'. |
java.lang.String |
getMessageDetailConvertTime()
Return custom detail error message that was set for creating FacesMessage,
for values that cannot be converted to Date
when type is set to 'time'. |
protected java.lang.Object |
getMessagePattern(javax.faces.context.FacesContext context,
java.lang.String key,
java.lang.Object[] params,
javax.faces.component.UIComponent component)
|
protected javax.faces.application.FacesMessage |
getParseErrorMessage(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component,
java.lang.String pattern,
java.lang.Object[] params)
|
java.lang.String |
getPattern()
Return the format pattern to be used when formatting and parsing dates and times. |
java.lang.String |
getSecondaryPattern()
Return the secondary pattern used to parse string when parsing by pattern or style fails. |
java.lang.String |
getTimeStyle()
Return the style to be used to format or parse times. |
java.util.TimeZone |
getTimeZone()
Return the TimeZone that is used to interpret a time value. |
java.lang.String |
getType()
Return the type of value to be formatted or parsed. |
javax.faces.el.ValueBinding |
getValueBinding(java.lang.String name)
Return the ValueBinding used to calculate the value for the
specified attribute name, if any. |
protected java.lang.String |
getViolationMessageKey(java.lang.String pattern)
|
int |
hashCode()
Returns the hash code for this Converter. |
boolean |
isTransient()
|
void |
restoreState(javax.faces.context.FacesContext context,
java.lang.Object state)
|
java.lang.Object |
saveState(javax.faces.context.FacesContext context)
|
void |
setDateStyle(java.lang.String dateStyle)
Set the style to be used to format or parse dates. |
void |
setHintBoth(java.lang.String hintBoth)
Custom hintBoth message. |
void |
setHintDate(java.lang.String hintDate)
Custom hintDate message. |
void |
setHintTime(java.lang.String hintTime)
Custom hintTime message. |
void |
setLocale(java.util.Locale locale)
Set the Locale to be used when parsing or formatting
dates and times. |
void |
setMessageDetailConvertBoth(java.lang.String convertBothMessageDetail)
Custom error message to be used, for creating detail part of the FacesMessage,
for date-time based value that cannot be converted to Date
when type is set to 'both'. |
void |
setMessageDetailConvertDate(java.lang.String convertDateMessageDetail)
Custom error message to be used, for creating detail part of the FacesMessage,
for values that cannot be converted to Date when the
pattern / secondary pattern is set or when type
is set to 'date'. |
void |
setMessageDetailConvertTime(java.lang.String convertTimeMessageDetail)
Custom error message to be used, for creating detail part of the FacesMessage,
for time based value that cannot be converted to date
when type is set to 'time'. |
void |
setPattern(java.lang.String pattern)
Set the format pattern to be used when formatting and parsing dates and times. |
void |
setSecondaryPattern(java.lang.String secondaryPattern)
Second pattern which will be used to parse string in getAsObject if pattern or styles fail. |
void |
setTimeStyle(java.lang.String timeStyle)
Set the style to be used to format or parse times. |
void |
setTimeZone(java.util.TimeZone timeZone)
Set the TimeZone used to interpret a time value. |
void |
setTransient(boolean isTransient)
|
void |
setType(java.lang.String type)
Set the type of value to be formatted or parsed. |
void |
setValueBinding(java.lang.String name,
javax.faces.el.ValueBinding binding)
Set the ValueBinding used to calculate the value for the
specified attribute if any. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String CONVERTER_ID
Standard converter id for this converter.
public static final java.lang.String CONVERT_DATE_MESSAGE_ID
The message identifier of the FacesMessage to be created if
the value cannot be converted to a date, when pattern
is null or not set and type is set to 'date'.
Or when failures occurs when value cannot be converted to a date
based on the pattern set. The message format string for this message
may optionally include {0}, {1}, {4}
placeholdes, which will be replaced by input value, component label
and example date based on the pattern or based on the
style when type is set to 'date'.
public static final java.lang.String CONVERT_TIME_MESSAGE_ID
The message identifier of the FacesMessage to be created if
the value cannot be converted date time object, when type
is set to 'time' and pattern is null or not set.
The message format string for this message may optionally include
{0}, {1}, {4}
placeholdes, which will be replaced by input value, component label
and a time example, based on the timeStyle
set in the converter.
public static final java.lang.String CONVERT_BOTH_MESSAGE_ID
The message identifier of the FacesMessage to be created if
the value cannot be converted to a date when type
is set to 'both' and pattern is either null or not set. The
message format string for this message may optionally include
{0}, {1}, {4}
placeholdes, which will be replaced by input value, component label
and a date-time example, based on the dateStyle and
timeStyle set in the converter.
| Constructor Detail |
|---|
public DateTimeConverter()
public DateTimeConverter(java.lang.String pattern)
pattern - a primary pattern; this will be used to format
and parser strings.
public DateTimeConverter(java.lang.String pattern,
java.lang.String secondaryPattern)
pattern - a primary pattern; this will be used to format
and parser strings.secondaryPattern - a 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.| Method Detail |
|---|
public java.lang.Object getAsObject(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component,
java.lang.String value)
Convert the specified string value, which is associated with
the specified UIComponent, into a java.util.Date object
based on the values set.
getAsObject in interface javax.faces.convert.ConvertergetAsObject in class javax.faces.convert.DateTimeConvertercontext - FacesContext for the request being processedcomponent - UIComponent with which this model object
value is associatedvalue - String value to be converted (may be null)
null if the value to convert is null,
otherwise return a java.util.Date object.
javax.faces.convert.ConverterException - if conversion cannot be successfully
performed
java.lang.NullPointerException - if context or
component is null
java.lang.IllegalArgumentException - if the value is of
type other than Date, String. The
value can be null.
public java.lang.String getAsString(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component,
java.lang.Object value)
Convert the model Date object value, into a String based on the pattern or styles.
getAsString in interface javax.faces.convert.ConvertergetAsString in class javax.faces.convert.DateTimeConvertercontext - FacesContext for the request being processedcomponent - UIComponent with which this model object
value is associatedvalue - Model object value to be converted
(may be null)
null,
otherwise the result of the conversion
javax.faces.convert.ConverterException - if conversion cannot be successfully
performed
java.lang.NullPointerException - if context or
component is nullpublic void setMessageDetailConvertDate(java.lang.String convertDateMessageDetail)
Custom error message to be used, for creating detail part of the FacesMessage,
for values that cannot be converted to Date when the
pattern / secondary pattern is set or when type
is set to 'date'.
CONVERT_DATE_MESSAGE_ID
convertDateMessageDetail - custom error message.public java.lang.String getMessageDetailConvertDate()
Return custom detail error message that was set for creating FacesMessage,
for values that cannot be converted to Date when
pattern / secondary pattern is set or
when type is set to 'date'.
setMessageDetailConvertDate(String)public void setMessageDetailConvertTime(java.lang.String convertTimeMessageDetail)
Custom error message to be used, for creating detail part of the FacesMessage,
for time based value that cannot be converted to date
when type is set to 'time'.
CONVERT_TIME_MESSAGE_ID
convertTimeMessageDetail - custom error message.public java.lang.String getMessageDetailConvertTime()
Return custom detail error message that was set for creating FacesMessage,
for values that cannot be converted to Date
when type is set to 'time'.
setMessageDetailConvertTime(java.lang.String)public void setMessageDetailConvertBoth(java.lang.String convertBothMessageDetail)
Custom error message to be used, for creating detail part of the FacesMessage,
for date-time based value that cannot be converted to Date
when type is set to 'both'.
CONVERT_BOTH_MESSAGE_ID
convertBothMessageDetail - custom error message.CONVERT_BOTH_MESSAGE_IDpublic java.lang.String getMessageDetailConvertBoth()
FacesMessage,
for values that cannot be converted to Date
when type is set to 'both'.
setMessageDetailConvertBoth(java.lang.String)public void setHintDate(java.lang.String hintDate)
Custom hintDate message.
Overrides default hint message
hintDate - Custom hint message.public java.lang.String getHintDate()
Return custom hintDate message.
setHintDate(String)public void setHintTime(java.lang.String hintTime)
Custom hintTime message.
Overrides default hint message
hintTime - Custom hint message.public java.lang.String getHintTime()
Return custom hintTime message.
setHintTime(String)public void setHintBoth(java.lang.String hintBoth)
Custom hintBoth message.
Overrides default hint message
hintBoth - Custom hint message.public java.lang.String getHintBoth()
Return custom hintBoth message.
setHintBoth(String)
protected java.util.Date getDate(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component)
This implementation checks to see if the component is a ValueHolder, and calls getValue() and returns the result if it is a Date instance.
component - The component to get the existing date from.
public void setLocale(java.util.Locale locale)
Set the Locale to be used when parsing or formatting
dates and times. If set to null, the Locale
stored in the UIViewRoot for the current
request will be utilized.
setLocale in class javax.faces.convert.DateTimeConverterlocale - The new Locale (or null)public java.util.Locale getLocale()
Return the Locale that was set.
If not explicitly set, the Locale stored
in the UIViewRoot for the current
request is used during call to getAsObject and
getAsString.
getLocale in class javax.faces.convert.DateTimeConverterpublic void setPattern(java.lang.String pattern)
Set the format pattern to be used when formatting and parsing
dates and times. Valid values are those supported by
java.text.SimpleDateFormat.
An invalid value will cause a ConverterException when
getAsObject() or getAsString() is called.
setPattern in class javax.faces.convert.DateTimeConverterpattern - The new format patternpublic java.lang.String getPattern()
Return the format pattern to be used when formatting and parsing dates and times.
getPattern in class javax.faces.convert.DateTimeConverterpublic void setTimeZone(java.util.TimeZone timeZone)
Set the TimeZone used to interpret a time value.
setTimeZone in class javax.faces.convert.DateTimeConvertertimeZone - The new time zonepublic java.util.TimeZone getTimeZone()
Return the TimeZone that is used to interpret a time value.
If not explicitly set or if a null value is set, then during call to
getAsObject and getAsString, the time zone set
for the web-app is used. If time zone is not set for the web-app then
the default time zone of GMT is used.
getTimeZone in class javax.faces.convert.DateTimeConverterpublic void setType(java.lang.String type)
Set the type of value to be formatted or parsed.
Valid values are both, date, or
time.
An invalid value will cause a IllegalStateException when
getAsObject() or getAsString() is called.
setType in class javax.faces.convert.DateTimeConvertertype - The new date stylepublic java.lang.String getType()
Return the type of value to be formatted or parsed.
If not explicitly set, the default type, date
is returned.
getType in class javax.faces.convert.DateTimeConverterpublic void setDateStyle(java.lang.String dateStyle)
Set the style to be used to format or parse dates. Valid values
are default, shortish
short, medium,
long, and full.
An invalid value will cause a IllegalStateException when
getAsObject() or getAsString() is called.
setDateStyle in class javax.faces.convert.DateTimeConverterdateStyle - The new style codepublic java.lang.String getDateStyle()
Return the style to be used to format or parse dates. If not set,
the default value, shortish, is returned.
getDateStyle in class javax.faces.convert.DateTimeConvertersetDateStyle(java.lang.String)public void setTimeStyle(java.lang.String timeStyle)
Set the style to be used to format or parse times. Valid values
are default, short,
medium, long, and full.
An invalid value will cause a IllegalStateException when
getAsObject() or getAsString() is called.
setTimeStyle in class javax.faces.convert.DateTimeConvertertimeStyle - The new style codepublic java.lang.String getTimeStyle()
Return the style to be used to format or parse times. If not set,
the default value, short, is returned.
getTimeStyle in class javax.faces.convert.DateTimeConverterpublic void setSecondaryPattern(java.lang.String secondaryPattern)
Second pattern which will be used to parse string in
getAsObject if pattern or styles fail. But is never
used for formatting to string in getAsString().
secondaryPattern - a 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.public java.lang.String getSecondaryPattern()
Return the secondary pattern used to parse string when parsing by pattern or style fails.
public boolean isTransient()
isTransient in interface javax.faces.component.StateHolderisTransient in class javax.faces.convert.DateTimeConverterpublic void setTransient(boolean isTransient)
setTransient in interface javax.faces.component.StateHoldersetTransient in class javax.faces.convert.DateTimeConverterpublic java.lang.Object saveState(javax.faces.context.FacesContext context)
saveState in interface javax.faces.component.StateHoldersaveState in class javax.faces.convert.DateTimeConverter
public void restoreState(javax.faces.context.FacesContext context,
java.lang.Object state)
restoreState in interface javax.faces.component.StateHolderrestoreState in class javax.faces.convert.DateTimeConverter
public void setValueBinding(java.lang.String name,
javax.faces.el.ValueBinding binding)
Set the ValueBinding used to calculate the value for the
specified attribute if any.
name - Name of the attribute for which to set a ValueBindingbinding - The ValueBinding to set, or null
to remove any currently set ValueBinding
java.lang.NullPointerException - if name
is null
java.lang.IllegalArgumentException - if name is not a valid
attribute of this converterpublic javax.faces.el.ValueBinding getValueBinding(java.lang.String name)
Return the ValueBinding used to calculate the value for the
specified attribute name, if any.
name - Name of the attribute or property for which to retrieve a
ValueBinding
java.lang.NullPointerException - if name
is null
java.lang.IllegalArgumentException - if name is not a valid
attribute of this converterpublic boolean equals(java.lang.Object object)
Compares this DateTimeConverter with the specified Object for equality.
equals in class java.lang.Objectobject - Object to which this DateTimeConverter is to be compared.
public int hashCode()
Returns the hash code for this Converter.
hashCode in class java.lang.Object
protected final java.text.DateFormat getDateFormat(javax.faces.context.FacesContext context,
java.lang.String pattern,
boolean forParsing)
throws javax.faces.convert.ConverterException
javax.faces.convert.ConverterExceptionprotected java.util.TimeZone getFormattingTimeZone(java.util.TimeZone tZone)
protected final javax.faces.application.FacesMessage getParseErrorMessage(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component,
java.lang.String pattern,
java.lang.Object[] params)
protected final java.lang.String getExample(javax.faces.context.FacesContext context)
protected java.lang.Object getMessagePattern(javax.faces.context.FacesContext context,
java.lang.String key,
java.lang.Object[] params,
javax.faces.component.UIComponent component)
protected java.lang.String getViolationMessageKey(java.lang.String pattern)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||