Top Description Fields Constructors Methods
jakarta.faces.convert

public Class EnumConverter

extends Object
implements Converter, PartialStateHolder
Class Inheritance
All Implemented Interfaces
jakarta.faces.component.PartialStateHolder, jakarta.faces.component.StateHolder, jakarta.faces.convert.Converter
Imports
jakarta.faces.component.PartialStateHolder, .UIComponent, jakarta.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 jakarta.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 jakarta.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
EnumConverter()

For StateHolder

public
EnumConverter(Class<T>
Class where the enum constants are taken from by the converter methods.
targetClass
)

Instantiates an enum converter with a class where enum constants are taken from.

Method Summary

Modifier and TypeMethod and Description
public void
clearInitialState()

Implements jakarta.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 jakarta.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 jakarta.faces.convert.Converter.getAsString.

Convert the enum constant given by the value argument into a String.

public boolean
initialStateMarked()

Implements jakarta.faces.component.PartialStateHolder.initialStateMarked.

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

public boolean
isTransient()

Implements jakarta.faces.component.StateHolder.isTransient.

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

public void
markInitialState()

Implements jakarta.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 jakarta.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 jakarta.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 jakarta.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 jakarta.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 jakarta.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()

For StateHolder

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

Instantiates an enum converter with a class where enum constants are taken from.

Parameters
targetClass:Class<T>

Class where the enum constants are taken from by the converter methods.

Method Detail

clearInitialStateback to summary
public void clearInitialState()

Implements jakarta.faces.component.PartialStateHolder.clearInitialState.

Doc from jakarta.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 jakarta.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 jakarta.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 jakarta.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 jakarta.faces.convert.Converter.getAsString.

FacesContext for the request being processed

component:UIComponent

Doc from jakarta.faces.convert.Converter.getAsString.

UIComponent with which this model object value is associated

value:Object

Doc from jakarta.faces.convert.Converter.getAsString.

Model object value to be converted (may be null)

Returns:String

Doc from jakarta.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 jakarta.faces.component.PartialStateHolder.initialStateMarked.

Doc from jakarta.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 jakarta.faces.component.StateHolder.isTransient.

Doc from jakarta.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 jakarta.faces.component.PartialStateHolder.markInitialState.

Doc from jakarta.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 jakarta.faces.component.StateHolder.restoreState.

Doc from jakarta.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 jakarta.faces.component.StateHolder.saveState.

Doc from jakarta.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 jakarta.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 jakarta.faces.component.StateHolder.setTransient.

Doc from jakarta.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