|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
javax.faces.convert Class DateTimeConverter
java.lang.Object javax.faces.convert.DateTimeConverter
- All Implemented Interfaces:
- StateHolder, Converter
public class DateTimeConverter
- extends Object
- implements Converter, StateHolder
java.util.Date
值的 Converter
实现。
getAsObject()
方法根据以下算法将 String 解析为 java.util.Date
:
- 如果指定的 String 为 null,则返回
null
。否则,在继续处理前去除前导空格和尾部的空格。 - 如果指定的 String(去除空格后)长度为 0,则返回
null
。 - 如果
locale
属性不为 null,则使用该Locale
管理解析。否则,使用UIViewRoot
的Locale
。 - 如果指定了
pattern
,则其语法必须遵守java.text.SimpleDateFormat
指定的规则。此类模式将用于解析,并且将忽略type
、dateStyle
和timeStyle
属性。 - 如果尚未指定
pattern
,则将根据type
属性进行解析,它应该为日期值或时间值,或者同时包含两者。将根据dateStyle
和timeStyle
指定的样式分别对包含的任何日期和时间值进行解析。 - 如果指定了
timezone
,则它必须传递给底层DateFormat
实例。否则,使用 "GMT" 时区。 - 无论是哪种情况,解析必须严格;给定的字符串必须严格遵守解析格式。
getAsString()
方法应该获取类型为 java.util.Date
(或子类)的值,并根据以下算法创建格式化 String:
- 如果指定的值为 null,则返回长度为 0 的 String。
- 如果指定的值为 String,则不加修改地返回该值。
- 如果
locale
属性不为 null,则使用该Locale
管理格式化。否则,使用UIViewRoot
的Locale
。 - 如果指定了
timezone
,则它必须传递给底层DateFormat
实例。否则,使用 "GMT" 时区。 - 如果指定了
pattern
,则其语法必须遵守java.text.SimpleDateFormat
指定的规则。此类模式将用于格式化,并且将忽略type
、dateStyle
和timeStyle
属性。 - 如果尚未指定
pattern
,则将根据type
属性进行格式化,这将在格式化的 String 中包含日期值或时间值,或者同时包含两者。将根据dateStyle
和timeStyle
指定的样式分别对包含的任何日期和时间值进行格式化。
Converter
implementation for java.util.Date
values.
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 thatLocale
for managing parsing. Otherwise, use theLocale
from theUIViewRoot
. - If a
pattern
has been specified, its syntax must conform the rules specified byjava.text.SimpleDateFormat
. Such a pattern will be used to parse, and thetype
,dateStyle
, andtimeStyle
properties will be ignored. - If a
pattern
has not been specified, parsing will be based on thetype
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 bydateStyle
andtimeStyle
, respectively. - If a
timezone
has been specified, it must be passed to the underlyingDateFormat
instance. Otherwise the "GMT" timezone is used. - In all cases, parsing must be non-lenient; the given string must strictly adhere to the parsing format.
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 thatLocale
for managing formatting. Otherwise, use theLocale
from theUIViewRoot
. - If a
timezone
has been specified, it must be passed to the underlyingDateFormat
instance. Otherwise the "GMT" timezone is used. - If a
pattern
has been specified, its syntax must conform the rules specified byjava.text.SimpleDateFormat
. Such a pattern will be used to format, and thetype
,dateStyle
, andtimeStyle
properties will be ignored. - If a
pattern
has not been specified, formatting will be based on thetype
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 bydateStyle
andtimeStyle
, respectively.
Field Summary | |
---|---|
static String |
CONVERTER_ID
The standard converter id for this converter. |
static String |
DATE_ID
The message identifier of the FacesMessage to be created if
the conversion to Date fails. |
static String |
DATETIME_ID
The message identifier of the FacesMessage to be created if
the conversion to DateTime fails. |
static String |
STRING_ID
The message identifier of the FacesMessage to be created if
the conversion of the DateTime value to
String fails. |
static String |
TIME_ID
The message identifier of the FacesMessage to be created if
the conversion to Time fails. |
Constructor Summary | |
---|---|
DateTimeConverter()
|
Method Summary | |
---|---|
Object |
getAsObject(FacesContext context,
UIComponent component,
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. |
String |
getAsString(FacesContext context,
UIComponent component,
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. |
String |
getDateStyle()
Return the style to be used to format or parse dates. |
Locale |
getLocale()
Return the Locale to be used when parsing or formatting
dates and times. |
String |
getPattern()
Return the format pattern to be used when formatting and parsing dates and times. |
String |
getTimeStyle()
Return the style to be used to format or parse times. |
TimeZone |
getTimeZone()
Return the TimeZone used to interpret a time value. |
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(FacesContext context,
Object state)
Perform any processing required to restore the state from the entries in the state Object. |
Object |
saveState(FacesContext context)
Gets the state of the instance as a Serializable Object. |
void |
setDateStyle(String dateStyle)
Set the style to be used to format or parse dates. |
void |
setLocale(Locale locale)
Set the Locale to be used when parsing or formatting
dates and times. |
void |
setPattern(String pattern)
Set the format pattern to be used when formatting and parsing dates and times. |
void |
setTimeStyle(String timeStyle)
Set the style to be used to format or parse times. |
void |
setTimeZone(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(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 String CONVERTER_ID
The standard converter id for this converter.
- See Also:
- Constant Field Values
英文文档:
DATE_ID
public static final String DATE_ID
The message identifier of the
FacesMessage
to be created if the conversion toDate
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 aString
whose value is the label of the input component that produced this message.
- See Also:
- Constant Field Values
英文文档:
TIME_ID
public static final String TIME_ID
The message identifier of the
FacesMessage
to be created if the conversion toTime
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 aString
whose value is the label of the input component that produced this message.
- See Also:
- Constant Field Values
英文文档:
DATETIME_ID
public static final String DATETIME_ID
The message identifier of the
FacesMessage
to be created if the conversion toDateTime
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 aString
whose value is the label of the input component that produced this message.
- See Also:
- Constant Field Values
英文文档:
STRING_ID
public static final String STRING_ID
The message identifier of the
FacesMessage
to be created if the conversion of theDateTime
value toString
fails. The message format string for this message may optionally include the following placeholders:{0}
relaced by the unconverted value.{1}
replaced by aString
whose value is the label of the input component that produced this message.
- See Also:
- Constant Field Values
Constructor Detail |
---|
public
DateTimeConverter()
英文文档:
DateTimeConverter
public DateTimeConverter()
Method Detail |
---|
public String
getDateStyle()
返回将用于格式化或解析日期的样式。如果未设置,则返回默认值 default
。
getDateStyle
public String getDateStyle()
Return the style to be used to format or parse dates. If not set, the default value,
default
, is returned.
public void
setDateStyle(String dateStyle)
设置将用于格式化或解析日期的样式。有效值有 default
、short
、medium
、long
和 full
。当调用 getAsObject()
或 getAsString()
时,无效值将导致 ConverterException
。
dateStyle | 新样式代码 |
setDateStyle
public void setDateStyle(String dateStyle)
Set the style to be used to format or parse dates. Valid values are
default
,short
,medium
,long
, andfull
. An invalid value will cause aConverterException
whengetAsObject()
orgetAsString()
is called.- Parameters:
dateStyle
- The new style code
public java.util.Locale
getLocale()
返回将在解析或格式化日期和时间时使用的 Locale
。如果没有明确设置,则返回存储在当前请求的 javax.faces.component.UIViewRoot
中的 Locale
。
getLocale
public Locale getLocale()
Return the
Locale
to be used when parsing or formatting dates and times. If not explicitly set, theLocale
stored in theUIViewRoot
for the current request is returned.
public void
setLocale(java.util.Locale locale)
设置将在解析或格式化日期和时间时使用的 Locale
。如果设置为 null
,则将使用存储在当前请求的 javax.faces.component.UIViewRoot
中的 Locale
。
locale |
新的 Locale (或者 null )。 |
setLocale
public void setLocale(Locale locale)
Set the
Locale
to be used when parsing or formatting dates and times. If set tonull
, theLocale
stored in theUIViewRoot
for the current request will be utilized.- Parameters:
locale
- The newLocale
(ornull
)
public String
getPattern()
返回将在格式化和解析日期和时间时使用的格式模式。
getPattern
public String getPattern()
Return the format pattern to be used when formatting and parsing dates and times.
public void
setPattern(String pattern)
设置将在格式化和解析日期和时间时使用的格式模式。有效值是 java.text.SimpleDateFormat
支持的那些值。当调用 getAsObject()
或 getAsString()
时,无效值将导致 ConverterException
。
pattern | 新的格式模式 |
setPattern
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 aConverterException
whengetAsObject()
orgetAsString()
is called.- Parameters:
pattern
- The new format pattern
public String
getTimeStyle()
返回将用于格式化或解析时间的样式。如果未设置,则返回默认值 default
。
getTimeStyle
public String getTimeStyle()
Return the style to be used to format or parse times. If not set, the default value,
default
, is returned.
public void
setTimeStyle(String timeStyle)
设置将用于格式化或解析时间的样式。有效值有 default
、short
、medium
、long
和 full
。当调用 getAsObject()
或 getAsString()
时,无效值将导致 ConverterException
。
timeStyle | 新样式代码 |
setTimeStyle
public void setTimeStyle(String timeStyle)
Set the style to be used to format or parse times. Valid values are
default
,short
,medium
,long
, andfull
. An invalid value will cause aConverterException
whengetAsObject()
orgetAsString()
is called.- Parameters:
timeStyle
- The new style code
public java.util.TimeZone
getTimeZone()
返回用来解释时间值的 TimeZone
。如果没有明确设置,则返回默认时区 GMT
。
getTimeZone
public TimeZone getTimeZone()
Return the
TimeZone
used to interpret a time value. If not explicitly set, the default time zone ofGMT
returned.
public void
setTimeZone(java.util.TimeZone timeZone)
设置用来解释时间值的 TimeZone
。
timeZone | 新时区 |
setTimeZone
public void setTimeZone(TimeZone timeZone)
Set the
TimeZone
used to interpret a time value.- Parameters:
timeZone
- The new time zone
public String
getType()
返回要格式化或解析的值的类型。如果没有明确设置,则返回默认类型 date
。
getType
public String getType()
Return the type of value to be formatted or parsed. If not explicitly set, the default type,
date
is returned.
public void
setType(String type)
设置要格式化或解析的值的类型。有效值为 both
、date
或 time
。当调用 getAsObject()
或 getAsString()
时,无效值将导致 ConverterException
。
type | 新日期样式 |
setType
public void setType(String type)
Set the type of value to be formatted or parsed. Valid values are
both
,date
, ortime
. An invalid value will cause aConverterException
whengetAsObject()
orgetAsString()
is called.- Parameters:
type
- The new date style
public Object
getAsObject(FacesContext context, UIComponent component, String value)
Throws | ConverterException: NullPointerException 如果无法成功执行转换 |
Throws | NullPointerException:
NullPointerException
如果 context 或 component 为 null |
getAsObject
public Object getAsObject(FacesContext context, UIComponent component, 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 interfaceConverter
- Parameters:
context
-FacesContext
for the request being processedcomponent
-UIComponent
with which this model object value is associatedvalue
- String value to be converted (may benull
)- Returns:
null
if the value to convert isnull
, otherwise the result of the conversion- Throws:
ConverterException
- if conversion cannot be successfully performedNullPointerException
- ifcontext
orcomponent
isnull
public String
getAsString(FacesContext context, UIComponent component, Object value)
Throws | ConverterException: NullPointerException 如果无法成功执行转换 |
Throws | NullPointerException:
NullPointerException
如果 context 或 component 为 null |
getAsString
public String getAsString(FacesContext context, UIComponent component, 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 interfaceConverter
- Parameters:
context
-FacesContext
for the request being processedcomponent
-UIComponent
with which this model object value is associatedvalue
- Model object value to be converted (may benull
)- Returns:
- a zero-length String if value is
null
, otherwise the result of the conversion - Throws:
ConverterException
- if conversion cannot be successfully performedNullPointerException
- ifcontext
orcomponent
isnull
public Object
saveState(FacesContext context)
英文文档:
saveState
public Object saveState(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 theStateHolder.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 theStateManager
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 interfaceStateHolder
public void
restoreState(FacesContext context, Object state)
英文文档:
restoreState
public void restoreState(FacesContext context, 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 theStateHolder.restoreState(javax.faces.context.FacesContext, java.lang.Object)
method on all those instances as well.- Specified by:
restoreState
in interfaceStateHolder
public boolean
isTransient()
英文文档:
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 interfaceStateHolder
public void
setTransient(boolean transientFlag)
英文文档:
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 interfaceStateHolder
- Parameters:
transientFlag
- boolean passtrue
if this Object will participate in state saving or restoring, otherwise passfalse
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Submit a bug or feature
Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!