Top Description Inners Fields Constructors Methods
javax.faces.convert

public Class DateTimeConverter

extends Object
implements Converter, PartialStateHolder
Class Inheritance
All Implemented Interfaces
javax.faces.component.PartialStateHolder, javax.faces.component.StateHolder, javax.faces.convert.Converter
Imports
java.text.DateFormat, .ParseException, .SimpleDateFormat, java.time.LocalDate, .LocalDateTime, .LocalTime, .OffsetDateTime, .OffsetTime, .ZonedDateTime, java.time.format.DateTimeFormatter, .DateTimeParseException, .FormatStyle, java.time.temporal.TemporalAccessor, .TemporalQuery, java.util.Date, .Locale, .TimeZone, javax.faces.component.PartialStateHolder, .UIComponent, javax.faces.context.FacesContext

Converter implementation for java.util.Date values.

The getAsObject() method parses a String into a java.util.Date, according to the following algorithm:

The getAsString() method expects a value of type java.util.Date (or a subclass), and creates a formatted String according to the following algorithm:

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
public static final String
CONVERTER_ID

The standard converter id for this converter.

public static final String
DATE_ID

The message identifier of the javax.faces.application.FacesMessage to be created if the conversion to Date fails.

private String
public static final String
DATETIME_ID

The message identifier of the javax.faces.application.FacesMessage to be created if the conversion to DateTime fails.

private static final TimeZone
private boolean
private Locale
private String
public static final String
STRING_ID

The message identifier of the javax.faces.application.FacesMessage to be created if the conversion of the DateTime value to String fails.

public static final String
TIME_ID

The message identifier of the javax.faces.application.FacesMessage to be created if the conversion to Time fails.

private String
private TimeZone
private boolean
private String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
clearInitialState()

Implements javax.faces.component.PartialStateHolder.clearInitialState.

Reset the PartialStateHolder to a non-delta tracking state.

public Object
getAsObject(FacesContext
FacesContext for the request being processed
context
,
UIComponent
UIComponent with which this model object value is associated
component
,
String
String value to be converted (may be null)
value
)

Implements javax.faces.convert.Converter.getAsObject.

Convert the specified string value, which is associated with the specified UIComponent, into a model data object that is appropriate for being stored during the Process Validations phase of the request processing lifecycle.

public String
getAsString(FacesContext
FacesContext for the request being processed
context
,
UIComponent
UIComponent with which this model object value is associated
component
,
Object
Model object value to be converted (may be null)
value
)

Implements javax.faces.convert.Converter.getAsString.

Convert the specified model object value, which is associated with the specified UIComponent, into a String that is suitable for being included in the response generated during the Render Response phase of the request processing lifeycle.

private DateTimeConverter.FormatWrapper
getDateFormat(Locale
The Locale used to select formatting and parsing conventions
locale
)

Return a DateFormat instance to use for formatting and parsing in this Converter.

public String

Returns:

the style
getDateStyle
()

Return the style to be used to format or parse dates.

private static FormatStyle
public Locale

Returns:

the Locale
getLocale
()

Return the Locale to be used when parsing or formatting dates and times.

private Locale
getLocale(FacesContext
The FacesContext for the current request
context
)

Return the Locale we will use for localizing our formatting and parsing processing.

public String

Returns:

the pattern
getPattern
()

Return the format pattern to be used when formatting and parsing dates and times.

private static int
getStyle(String
Name of the style for which to return a constant
name
)

Return the style constant for the specified style name.

public String

Returns:

the time style
getTimeStyle
()

Return the style to be used to format or parse times.

public TimeZone

Returns:

the TimeZone
getTimeZone
()

Return the TimeZone used to interpret a time value.

public String

Returns:

the type
getType
()

Return the type of value to be formatted or parsed.

public boolean
initialStateMarked()

Implements javax.faces.component.PartialStateHolder.initialStateMarked.

Return true if delta state changes are being tracked, otherwise false

private static boolean
public boolean
isTransient()

Implements javax.faces.component.StateHolder.isTransient.

If true, the Object implementing this interface must not participate in state saving or restoring.

public void
markInitialState()

Implements javax.faces.component.PartialStateHolder.markInitialState.

The runtime must ensure that the markInitialState method is called on each instance of this interface in the view at the appropriate time to indicate the component is in its initial state.

public void
restoreState(FacesContext
the Faces context.
context
,
Object
the state.
state
)

Implements javax.faces.component.StateHolder.restoreState.

Perform any processing required to restore the state from the entries in the state Object.

public Object
saveState(FacesContext
the Faces context.
context
)

Implements javax.faces.component.StateHolder.saveState.

Gets the state of the instance as a Serializable Object.

public void
setDateStyle(String
The new style code
dateStyle
)

Set the style to be used to format or parse dates.

public void
setLocale(Locale
The new Locale (or null)
locale
)

Set the Locale to be used when parsing or formatting dates and times.

public void
setPattern(String
The new format pattern
pattern
)

Set the format pattern to be used when formatting and parsing dates and times.

public void
setTimeStyle(String
The new style code
timeStyle
)

Set the style to be used to format or parse times.

public void
setTimeZone(TimeZone
The new time zone
timeZone
)

Set the TimeZone used to interpret a time value.

public void
setTransient(boolean
boolean pass true if this Object will not participate in state saving or restoring, otherwise pass false.
transientFlag
)

Implements javax.faces.component.StateHolder.setTransient.

Denotes whether or not the Object implementing this interface must or must not participate in state saving or restoring.

public void
setType(String
The new date style
type
)

Set the type of value to be formatted or parsed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CONVERTER_IDback to summary
public static final String CONVERTER_ID

The standard converter id for this converter.

DATE_IDback to summary
public static final String DATE_ID

The message identifier of the javax.faces.application.FacesMessage to be created if the conversion to Date fails. The message format string for this message may optionally include the following placeholders:

  • {0} replaced by the unconverted value.
  • {1} replaced by an example value.
  • {2} replaced by a String whose value is the label of the input component that produced this message.
dateStyleback to summary
private String dateStyle
DATETIME_IDback to summary
public static final String DATETIME_ID

The message identifier of the javax.faces.application.FacesMessage to be created if the conversion to DateTime fails. The message format string for this message may optionally include the following placeholders:

  • {0} replaced by the unconverted value.
  • {1} replaced by an example value.
  • {2} replaced by a String whose value is the label of the input component that produced this message.
DEFAULT_TIME_ZONEback to summary
private static final TimeZone DEFAULT_TIME_ZONE
initialStateback to summary
private boolean initialState
localeback to summary
private Locale locale
patternback to summary
private String pattern
STRING_IDback to summary
public static final String STRING_ID

The message identifier of the javax.faces.application.FacesMessage to be created if the conversion of the DateTime value to String fails. The message format string for this message may optionally include the following placeholders:

  • {0} relaced by the unconverted value.
  • {1} replaced by a String whose value is the label of the input component that produced this message.
TIME_IDback to summary
public static final String TIME_ID

The message identifier of the javax.faces.application.FacesMessage to be created if the conversion to Time fails. The message format string for this message may optionally include the following placeholders:

  • {0} replaced by the unconverted value.
  • {1} replaced by an example value.
  • {2} replaced by a String whose value is the label of the input component that produced this message.
timeStyleback to summary
private String timeStyle
timeZoneback to summary
private TimeZone timeZone
transientFlagback to summary
private boolean transientFlag
typeback to summary
private String type

Constructor Detail

DateTimeConverterback to summary
public DateTimeConverter()

Method Detail

clearInitialStateback to summary
public void clearInitialState()

Implements javax.faces.component.PartialStateHolder.clearInitialState.

Doc from javax.faces.component.PartialStateHolder.clearInitialState.

Reset the PartialStateHolder to a non-delta tracking state.

Annotations
@Override
getAsObjectback to summary
public Object getAsObject(FacesContext context, UIComponent component, String value)

Implements javax.faces.convert.Converter.getAsObject.

Doc from javax.faces.convert.Converter.getAsObject.

Convert the specified string value, which is associated with the specified UIComponent, into a model data object that is appropriate for being stored during the Process Validations phase of the request processing lifecycle.

Parameters
context:FacesContext

FacesContext for the request being processed

component:UIComponent

UIComponent with which this model object value is associated

value:String

String value to be converted (may be null)

Returns:Object

null if the value to convert is null, otherwise the result of the conversion

Annotations
@Override
Exceptions
ConverterException:
if conversion cannot be successfully performed
NullPointerException:
if context or component is null
getAsStringback to summary
public String getAsString(FacesContext context, UIComponent component, Object value)

Implements javax.faces.convert.Converter.getAsString.

Doc from javax.faces.convert.Converter.getAsString.

Convert the specified model object value, which is associated with the specified UIComponent, into a String that is suitable for being included in the response generated during the Render Response phase of the request processing lifeycle.

Parameters
context:FacesContext

FacesContext for the request being processed

component:UIComponent

UIComponent with which this model object value is associated

value:Object

Model object value to be converted (may be null)

Returns:String

a zero-length String if value is null, otherwise the result of the conversion

Annotations
@Override
Exceptions
ConverterException:
if conversion cannot be successfully performed
NullPointerException:
if context or component is null
getDateFormatback to summary
private DateTimeConverter.FormatWrapper getDateFormat(Locale locale)

Return a DateFormat instance to use for formatting and parsing in this Converter.

Parameters
locale:Locale

The Locale used to select formatting and parsing conventions

Exceptions
ConverterException:
if no instance can be created
getDateStyleback to summary
public String getDateStyle()

Return the style to be used to format or parse dates. If not set, the default value, default, is returned.

Returns:String

the style

getFormatStyleback to summary
private static FormatStyle getFormatStyle(String name)
getLocaleback to summary
public Locale getLocale()

Return the Locale to be used when parsing or formatting dates and times. If not explicitly set, the Locale stored in the javax.faces.component.UIViewRoot for the current request is returned.

Returns:Locale

the Locale

getLocaleback to summary
private Locale getLocale(FacesContext context)

Return the Locale we will use for localizing our formatting and parsing processing.

Parameters
context:FacesContext

The FacesContext for the current request

getPatternback to summary
public String getPattern()

Return the format pattern to be used when formatting and parsing dates and times.

Returns:String

the pattern

getStyleback to summary
private static int getStyle(String name)

Return the style constant for the specified style name.

Parameters
name:String

Name of the style for which to return a constant

Exceptions
ConverterException:
if the style name is not valid
getTimeStyleback to summary
public String getTimeStyle()

Return the style to be used to format or parse times. If not set, the default value, default, is returned.

Returns:String

the time style

getTimeZoneback to summary
public TimeZone getTimeZone()

Return the TimeZone used to interpret a time value. If not explicitly set, the default time zone of GMT returned.

Returns:TimeZone

the TimeZone

getTypeback to summary
public String getType()

Return the type of value to be formatted or parsed. If not explicitly set, the default type, date is returned.

Returns:String

the type

initialStateMarkedback to summary
public boolean initialStateMarked()

Implements javax.faces.component.PartialStateHolder.initialStateMarked.

Doc from javax.faces.component.PartialStateHolder.initialStateMarked.

Return true if delta state changes are being tracked, otherwise false

Returns:boolean

true if the initial state is marked, false otherwise.

Annotations
@Override
isJavaTimeTypeback to summary
private static boolean isJavaTimeType(String type)
isTransientback to summary
public boolean isTransient()

Implements javax.faces.component.StateHolder.isTransient.

Doc from javax.faces.component.StateHolder.isTransient.

If true, the Object implementing this interface must not participate in state saving or restoring.

Returns:boolean

true if transient, false otherwise.

Annotations
@Override
markInitialStateback to summary
public void markInitialState()

Implements javax.faces.component.PartialStateHolder.markInitialState.

Doc from javax.faces.component.PartialStateHolder.markInitialState.

The runtime must ensure that the markInitialState method is called on each instance of this interface in the view at the appropriate time to indicate the component is in its initial state. The implementor of the interface must ensure that initialStateMarked returns true from the time markInitialState() is called until clearInitialState is called, after which time initialStateMarked() must return false. Also, during the time that the instance returns true from initialStateMarked(), the implementation must return only the state that has changed in its implementation of StateHolder#saveState.

Annotations
@Override
restoreStateback to summary
public void restoreState(FacesContext context, Object state)

Implements javax.faces.component.StateHolder.restoreState.

Doc from javax.faces.component.StateHolder.restoreState.

Perform any processing required to restore the state from the entries in the state Object.

If the class that implements this interface has references to instances that also implement StateHolder (such as a UIComponent with event handlers, validators, etc.) this method must call the restoreState method on all those instances as well.

If the state argument is null, take no action and return.

Parameters
context:FacesContext

the Faces context.

state:Object

the state.

Annotations
@Override
saveStateback to summary
public Object saveState(FacesContext context)

Implements javax.faces.component.StateHolder.saveState.

Doc from javax.faces.component.StateHolder.saveState.

Gets the state of the instance as a Serializable Object.

If the class that implements this interface has references to instances that implement StateHolder (such as a UIComponent with event handlers, validators, etc.) this method must call the saveState method on all those instances as well. This method must not save the state of children and facets. That is done via the javax.faces.application.StateManager

This method must not alter the state of the implementing object. In other words, after executing this code:


Object state = component.saveState(facesContext);

component should be the same as before executing it.

The return from this method must be Serializable

Parameters
context:FacesContext

the Faces context.

Returns:Object

the saved state.

Annotations
@Override
setDateStyleback to summary
public void setDateStyle(String dateStyle)

Set the style to be used to format or parse dates. Valid values are default, short, medium, long, and full. An invalid value will cause a ConverterException when getAsObject() or getAsString() is called.

Parameters
dateStyle:String

The new style code

setLocaleback to summary
public void setLocale(Locale locale)

Set the Locale to be used when parsing or formatting dates and times. If set to null, the Locale stored in the javax.faces.component.UIViewRoot for the current request will be utilized.

Parameters
locale:Locale

The new Locale (or null)

setPatternback to summary
public void setPattern(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.

Parameters
pattern:String

The new format pattern

setTimeStyleback to summary
public void setTimeStyle(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 ConverterException when getAsObject() or getAsString() is called.

Parameters
timeStyle:String

The new style code

setTimeZoneback to summary
public void setTimeZone(TimeZone timeZone)

Set the TimeZone used to interpret a time value.

Parameters
timeZone:TimeZone

The new time zone

setTransientback to summary
public void setTransient(boolean transientFlag)

Implements javax.faces.component.StateHolder.setTransient.

Doc from javax.faces.component.StateHolder.setTransient.

Denotes whether or not the Object implementing this interface must or must not participate in state saving or restoring.

Parameters
transientFlag:boolean

boolean pass true if this Object will not participate in state saving or restoring, otherwise pass false.

Annotations
@Override
setTypeback to summary
public void setType(String type)

Set the type of value to be formatted or parsed. Valid values are both, date, time localDate, localDateTime, localTime, offsetTime, offsetDateTime, or zonedDateTime. The values starting with "local", "offset" and "zoned" correspond to Java SE 8 Date Time API classes in package java.time with the name derived by upper casing the first letter. For example, java.time.LocalDate for the value "localDate". An invalid value will cause a ConverterException when getAsObject() or getAsString() is called.

Parameters
type:String

The new date style

javax.faces.convert back to summary

private Class DateTimeConverter.FormatWrapper

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final DateFormat
private final DateTimeFormatter
private final TemporalQuery<R>

Constructor Summary

AccessConstructor and Description
private
private

Method Summary

Modifier and TypeMethod and Description
private String
private String
private Object
private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dfback to summary
private final DateFormat df
dtfback to summary
private final DateTimeFormatter dtf
fromback to summary
private final TemporalQuery<R> from

Constructor Detail

FormatWrapperback to summary
private FormatWrapper(DateFormat wrapped)
FormatWrapperback to summary
private FormatWrapper(DateTimeFormatter dtf, TemporalQuery<R> from)

Method Detail

formatback to summary
private String format(Object obj)
formatNowback to summary
private String formatNow()
parseback to summary
private Object parse(CharSequence text) throws ParseException
setTimeZoneback to summary
private void setTimeZone(TimeZone zone)