public class EnumConverter extends Object implements Converter, PartialStateHolder
Converter
implementation
for java.lang.Enum
(and enum primitive) values.
Modifier and Type | Field and Description |
---|---|
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. |
DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE_PARAM_NAME
Constructor and Description |
---|
EnumConverter() |
EnumConverter(Class targetClass) |
Modifier and Type | Method and Description |
---|---|
void |
clearInitialState()
Reset the PartialStateHolder to a non-delta tracking state. |
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 |
initialStateMarked()
Return |
boolean |
isTransient()
If true, the Object implementing this interface must not
participate in state saving or restoring.
|
void |
markInitialState()
The runtime must ensure that the
|
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.
|
public static final String CONVERTER_ID
The standard converter id for this converter.
public static final String ENUM_ID
The message identifier of the FacesMessage
to be created if
the conversion to Enum
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 a String
whose value
is the label of the input component that produced this message.public static final 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. The message format
string for this message may optionally include the following
placeholders:
{0}
replaced by the unconverted value.{1}
replaced by a String
whose value
is the label of the input component that produced this message.public EnumConverter()
public EnumConverter(Class targetClass)
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 a ConverterException
containing the ENUM_NO_CLASS_ID
message with proper
parameters. If the value
argument is null
or it has a length of zero, return null
.
Otherwise, perform the equivalent of Enum.valueOf
using
target class and value
and return the Object
.
If the conversion fails, throw a ConverterException
containing the ENUM_ID
message with proper parameters.
getAsObject
in interface Converter
context
- the FacesContext
for this request.component
- the UIComponent
to which this value
will be applied.value
- the String value
to be converted to
Object
.null
if the value to convert is null
,
otherwise the result of the conversionConverterException
- if conversion cannot be successfully
performedNullPointerException
- if context
or
component
is null
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 a
ConverterException
containing the ENUM_NO_CLASS_ID
message with proper parameters. If the
value
argument is null
, return
null
. If the value is an instance of the provided
target class, return its string value by casting it to a
java.lang.Enum
and returning the result of calling
the name()
method. Otherwise, throw a ConverterException
containing the ENUM_ID
message with
proper parameters.
getAsString
in interface Converter
context
- 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 conversionConverterException
- if conversion cannot be successfully
performedNullPointerException
- if context
or
component
is null
public void restoreState(FacesContext facesContext, Object object)
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.
If the state
argument is null
, take no action and return.
restoreState
in interface StateHolder
public Object saveState(FacesContext facesContext)
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
saveState
in interface StateHolder
public void setTransient(boolean b)
StateHolder
Denotes whether or not the Object implementing this interface must or must not participate in state saving or restoring.
setTransient
in interface StateHolder
b
- boolean pass true
if this
Object will not
participate in state saving or restoring, otherwise pass
false
.public boolean isTransient()
StateHolder
If true, the Object implementing this interface must not participate in state saving or restoring.
isTransient
in interface StateHolder
public void markInitialState()
PartialStateHolder
The runtime must ensure that the
PartialStateHolder.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 PartialStateHolder.initialStateMarked()
returns
true
from the time markInitialState()
is called until PartialStateHolder.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(javax.faces.context.FacesContext)
.
markInitialState
in interface PartialStateHolder
public boolean initialStateMarked()
PartialStateHolder
Return true
if delta
state changes are being tracked, otherwise false
initialStateMarked
in interface PartialStateHolder
public void clearInitialState()
PartialStateHolder
Reset the PartialStateHolder to a non-delta tracking state.
clearInitialState
in interface PartialStateHolder
Copyright © 2017 JBoss by Red Hat. All rights reserved.