javax.faces.convert
Class DateTimeConverter

java.lang.Object
  |
  +--javax.faces.convert.DateTimeConverter
All Implemented Interfaces:
Converter, StateHolder

public class DateTimeConverter
extends java.lang.Object
implements Converter, StateHolder

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:


Field Summary
static java.lang.String CONVERTER_ID
          The standard converter id for this converter.
 
Constructor Summary
DateTimeConverter()
           
 
Method Summary
 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 model data object that is appropriate for being stored during the Apply Request Values phase of the request processing lifecycle.
 java.lang.String getAsString(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.Object value)
          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.
 java.lang.String getDateStyle()
          Return the style to be used to format or parse dates.
 java.util.Locale getLocale()
          Return the Locale to be used when parsing or formatting dates and times.
 java.lang.String getPattern()
          Return the format pattern to be used when formatting and parsing dates and times.
 java.lang.String getTimeStyle()
          Return the style to be used to format or parse times.
 java.util.TimeZone getTimeZone()
          Return the TimeZone used to interpret a time value.
 java.lang.String getType()
          Return the type of value to be formatted or parsed.
 boolean isTransient()
          If true, the Object implementing this interface must not participate in state saving or restoring.
 void restoreState(javax.faces.context.FacesContext context, java.lang.Object state)
           Perform any processing required to restore the state from the entries in the state Object.
 java.lang.Object saveState(javax.faces.context.FacesContext context)
           Gets the state of the instance as a Serializable Object.
 void setDateStyle(java.lang.String dateStyle)
          Set the style to be used to format or parse dates.
 void setLocale(java.util.Locale locale)
          Set the Locale to be used when parsing or formatting dates and times.
 void setPattern(java.lang.String pattern)
          Set the format pattern to be used when formatting and parsing dates and times.
 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 transientFlag)
          Denotes whether or not the Object implementing this interface must or must not participate in state saving or restoring.
 void setType(java.lang.String type)
          Set the type of value to be formatted or parsed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONVERTER_ID

public static final java.lang.String CONVERTER_ID

The standard converter id for this converter.

See Also:
Constant Field Values
Constructor Detail

DateTimeConverter

public DateTimeConverter()
Method Detail

getDateStyle

public java.lang.String getDateStyle()

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


setDateStyle

public void setDateStyle(java.lang.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 - The new style code

getLocale

public java.util.Locale getLocale()

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


setLocale

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.

Parameters:
locale - The new Locale (or null)

getPattern

public java.lang.String getPattern()

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


setPattern

public 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.

Parameters:
pattern - The new format pattern

getTimeStyle

public java.lang.String getTimeStyle()

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


setTimeStyle

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 ConverterException when getAsObject() or getAsString() is called.

Parameters:
timeStyle - The new style code

getTimeZone

public java.util.TimeZone getTimeZone()

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


setTimeZone

public void setTimeZone(java.util.TimeZone timeZone)

Set the TimeZone used to interpret a time value.

Parameters:
timeZone - The new time zone

getType

public java.lang.String getType()

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


setType

public 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 ConverterException when getAsObject() or getAsString() is called.

Parameters:
type - The new date style

getAsObject

public java.lang.Object getAsObject(javax.faces.context.FacesContext context,
                                    javax.faces.component.UIComponent component,
                                    java.lang.String value)
Description copied from interface: Converter

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 Apply Request Values phase of the request processing lifecycle.

Specified by:
getAsObject in interface Converter
Parameters:
context - FacesContext for the request being processed
component - UIComponent with which this model object value is associated
value - String value to be converted (may be null)
Returns:
null if the value to convert is null, otherwise the result of the conversion
Throws:
ConverterException - if conversion cannot be successfully performed
java.lang.NullPointerException - if context or component is null

getAsString

public java.lang.String getAsString(javax.faces.context.FacesContext context,
                                    javax.faces.component.UIComponent component,
                                    java.lang.Object value)
Description copied from interface: Converter

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.

Specified by:
getAsString in interface Converter
Parameters:
context - FacesContext for the request being processed
component - UIComponent with which this model object value is associated
value - Model object value to be converted (may be null)
Returns:
a zero-length String if value is null, otherwise the result of the conversion
Throws:
ConverterException - if conversion cannot be successfully performed
java.lang.NullPointerException - if context or component is null

saveState

public java.lang.Object saveState(javax.faces.context.FacesContext context)
Description copied from interface: StateHolder

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 StateHolder.saveState(javax.faces.context.FacesContext) method on all those instances as well. This method must not save the state of children and facets. That is done via the 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

Specified by:
saveState in interface StateHolder

restoreState

public void restoreState(javax.faces.context.FacesContext context,
                         java.lang.Object state)
Description copied from interface: StateHolder

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 StateHolder.restoreState(javax.faces.context.FacesContext, java.lang.Object) method on all those instances as well.

Specified by:
restoreState in interface StateHolder

isTransient

public boolean isTransient()
Description copied from interface: StateHolder

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

Specified by:
isTransient in interface StateHolder

setTransient

public void setTransient(boolean transientFlag)
Description copied from interface: StateHolder

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

Specified by:
setTransient in interface StateHolder
Parameters:
transientFlag - boolean pass true if this Object will participate in state saving or restoring, otherwise pass false.


Copyright ? 2002-2004 Sun Microsystems, Inc. All Rights Reserved.