|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
javax.faces.convert Class EnumConverter
java.lang.Object javax.faces.convert.EnumConverter
- All Implemented Interfaces:
- StateHolder, Converter
public class EnumConverter
- extends Object
- implements Converter, StateHolder
java.lang.Enum
(以及 enum 基本类型)值的 Converter
实现。
since | 1.2 |
Converter
implementation for java.lang.Enum
(and enum primitive) values.
- Since:
- 1.2
Field Summary | |
---|---|
static String |
CONVERTER_ID
The standard converter id for this converter. |
static String |
ENUM_ID
The message identifier of the FacesMessage to be created if
the conversion to Enum fails. |
static String |
ENUM_NO_CLASS_ID
The message identifier of the FacesMessage to be created if
the conversion to Enum fails and no target class has been
provided. |
Constructor Summary | |
---|---|
EnumConverter()
|
|
EnumConverter(Class targetClass)
|
Method Summary | |
---|---|
Object |
getAsObject(FacesContext context,
UIComponent component,
String value)
Convert the value argument to one of the enum
constants of the class provided in our constructor. |
String |
getAsString(FacesContext context,
UIComponent component,
Object value)
Convert the enum constant given by the value
argument into a String. |
boolean |
isTransient()
If true, the Object implementing this interface must not participate in state saving or restoring. |
void |
restoreState(FacesContext facesContext,
Object object)
Perform any processing required to restore the state from the entries in the state Object. |
Object |
saveState(FacesContext facesContext)
Gets the state of the instance as a Serializable Object. |
void |
setTransient(boolean b)
Denotes whether or not the Object implementing this interface must or must not participate in state saving or restoring. |
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
英文文档:
ENUM_ID
public static final String ENUM_ID
The message identifier of the
FacesMessage
to be created if the conversion toEnum
fails. The message format string for this message may optionally include the following placeholders:{0}
replaced by the unconverted value.{1}
replaced by one of the enum constants or the empty string if none can be found.{2}
replaced by aString
whose value is the label of the input component that produced this message.
- See Also:
- Constant Field Values
英文文档:
ENUM_NO_CLASS_ID
public static final String ENUM_NO_CLASS_ID
The message identifier of the
FacesMessage
to be created if the conversion toEnum
fails and no target class has been provided. The message format string for this message may optionally include the following placeholders:{0}
replaced 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
EnumConverter()
英文文档:
EnumConverter
public EnumConverter()
public
EnumConverter(Class<T> targetClass)
英文文档:
EnumConverter
public EnumConverter(Class targetClass)
Method Detail |
---|
public Object
getAsObject(FacesContext context, UIComponent component, String value)
将 value
参数转换为在构造方法中提供的类枚举常量之一。如果没有向此实例的构造方法提供任何目标类参数,则抛出包含 #ENUM_NO_CLASS_ID
消息和相应参数的 ConverterException
。如果 value
参数为 null
或它的长度为 0,则返回 null
。否则,使用目标类和 value
执行等效的 Enum.valueOf
并返回 Object
。如果转换失败,则抛出一个 ConverterException
,它包含 #ENUM_ID
消息和相应的参数。
context |
此请求的 FacesContext 。 |
component |
将应用此值的 UIComponent 。 |
value |
要转换为 Object 的 String value 。 |
Throws | ConverterException: NullPointerException 如果无法成功执行转换 |
Throws | NullPointerException:
NullPointerException
如果 context 或 component 为 null |
getAsObject
public Object getAsObject(FacesContext context, UIComponent component, String value)
Convert the
value
argument to one of the enum constants of the class provided in our constructor. If no target class argument has been provided to the constructor of this instance, throw aConverterException
containing theENUM_NO_CLASS_ID
message with proper parameters. If thevalue
argument isnull
or it has a length of zero, returnnull
. Otherwise, perform the equivalent ofEnum.valueOf
using target class andvalue
and return theObject
. If the conversion fails, throw aConverterException
containing theENUM_ID
message with proper parameters.- Specified by:
getAsObject
in interfaceConverter
- Parameters:
context
- theFacesContext
for this request.component
- theUIComponent
to which this value will be applied.value
- the Stringvalue
to be converted toObject
.- 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)
将由 value
参数给定的枚举常量转换为 String。如果没有向此实例的构造方法提供任何目标类参数,则抛出包含 #ENUM_NO_CLASS_ID
消息和相应参数的 ConverterException
。如果 value
参数为 null
,则返回 null
。如果该值为提供的目标类的实例,则返回它的字符串值 (value.toString()
)。否则,抛出一个 ConverterException
,它包含 #ENUM_ID
消息和相应的参数。
Throws | ConverterException: NullPointerException 如果无法成功执行转换 |
Throws | NullPointerException:
NullPointerException
如果 context 或 component 为 null |
getAsString
public String getAsString(FacesContext context, UIComponent component, Object value)
Convert the enum constant given by the
value
argument into a String. If no target class argument has been provided to the constructor of this instance, throw aConverterException
containing theENUM_NO_CLASS_ID
message with proper parameters. If thevalue,/code> argument is
null
, returnnull
. If the value is an instance of the provided target class, return its string value (value.toString()
). Otherwise, throw aConverterException
containing theENUM_ID
message with proper parameters.- 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 void
restoreState(FacesContext facesContext, Object object)
英文文档:
restoreState
public void restoreState(FacesContext facesContext, Object object)
- 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 Object
saveState(FacesContext facesContext)
英文文档:
saveState
public Object saveState(FacesContext facesContext)
- 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
setTransient(boolean b)
英文文档:
setTransient
public void setTransient(boolean b)
- 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:
b
- boolean passtrue
if this Object will participate in state saving or restoring, otherwise passfalse
.
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
|
|||||||||
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 : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!