Top Description Fields Constructors Methods
javax.faces.convert

public Class EnumConverter

extends Object
implements Converter, PartialStateHolder
Class Inheritance
All Implemented Interfaces
javax.faces.component.PartialStateHolder, javax.faces.component.StateHolder, javax.faces.convert.Converter
Imports
javax.faces.component.UIComponent, .PartialStateHolder, javax.faces.context.FacesContext

Converter implementation for java.lang.Enum (and enum primitive) values.

Since
1.2

Field Summary

Modifier and TypeField and Description
public static final String
CONVERTER_ID

The standard converter id for this converter.

public static final String
ENUM_ID

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

public static final String
ENUM_NO_CLASS_ID

The message identifier of the javax.faces.application.FacesMessage to be created if the conversion to Enum fails and no target class has been provided.

private boolean
private boolean
private Class<? extends Enum<E extends Enum<E>>>

Constructor Summary

AccessConstructor and Description
public
public
EnumConverter(Class<T> targetClass)

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
the FacesContext for this request.
context
,
UIComponent
the UIComponent to which this value will be applied.
component
,
String
the String value to be converted to Object.
value
)

Implements javax.faces.convert.Converter.getAsObject.

Convert the value argument to one of the enum constants of the class provided in our constructor.

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 enum constant given by the value argument into a String.

public boolean
initialStateMarked()

Implements javax.faces.component.PartialStateHolder.initialStateMarked.

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

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.
facesContext
,
Object
the state.
object
)

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.
facesContext
)

Implements javax.faces.component.StateHolder.saveState.

Gets the state of the instance as a Serializable Object.

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

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.

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.

ENUM_IDback to summary
public static final String ENUM_ID

The message identifier of the javax.faces.application.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.
ENUM_NO_CLASS_IDback to summary
public static final String ENUM_NO_CLASS_ID

The message identifier of the javax.faces.application.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.
initialStateback to summary
private boolean initialState
isTransientback to summary
private boolean isTransient
targetClassback to summary
private Class<? extends Enum<E extends Enum<E>>> targetClass

Constructor Detail

EnumConverterback to summary
public EnumConverter()
EnumConverterback to summary
public EnumConverter(Class<T> targetClass)

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.

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.

Parameters
context:FacesContext

the FacesContext for this request.

component:UIComponent

the UIComponent to which this value will be applied.

value:String

the String value to be converted to Object.

Returns:Object

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

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.

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 the empty String. 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.

Parameters
context:FacesContext

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

FacesContext for the request being processed

component:UIComponent

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

UIComponent with which this model object value is associated

value:Object

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

Model object value to be converted (may be null)

Returns:String

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

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
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
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 facesContext, Object object)

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
facesContext:FacesContext

the Faces context.

object:Object

the state.

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

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
facesContext:FacesContext

the Faces context.

Returns:Object

the saved state.

Annotations
@Override
setTransientback to summary
public void setTransient(boolean b)

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
b:boolean

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

Annotations
@Override