- java.lang.Object
-
- javax.faces.convert.EnumConverter
-
- All Implemented Interfaces:
- PartialStateHolder, StateHolder, Converter
public class EnumConverter extends Object implements Converter, PartialStateHolder
Converter
implementation forjava.lang.Enum
(and enum primitive) values.- Since:
- 1.2
-
-
Field Summary
Fields 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 theFacesMessage
to be created if the conversion toEnum
fails.static String
ENUM_NO_CLASS_ID
The message identifier of theFacesMessage
to be created if the conversion toEnum
fails and no target class has been provided.-
Fields inherited from interface javax.faces.convert.Converter
DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE_PARAM_NAME
-
-
Constructor Summary
Constructors Constructor and Description EnumConverter()
EnumConverter(Class targetClass)
-
Method Summary
All Methods Instance Methods Concrete Methods 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 thevalue
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 thevalue
argument into a String.boolean
initialStateMarked()
Return
true
if delta state changes are being tracked, otherwisefalse
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
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.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 aSerializable
Object.void
setTransient(boolean b)
Denotes whether or not the Object implementing this interface must or must not participate in state saving or restoring.
-
-
-
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
-
EnumConverter
public EnumConverter()
-
EnumConverter
public EnumConverter(Class targetClass)
-
-
Method Detail
-
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
-
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
argument isnull
, returnnull
. If the value is an instance of the provided target class, return its string value by casting it to ajava.lang.Enum
and returning the result of calling thename()
method. 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
-
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.If the
state
argument isnull
, take no action and return.- Specified by:
restoreState
in interfaceStateHolder
-
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
-
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 not participate in state saving or restoring, otherwise passfalse
.
-
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
-
markInitialState
public void markInitialState()
Description copied from interface: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 thatPartialStateHolder.initialStateMarked()
returnstrue
from the timemarkInitialState()
is called untilPartialStateHolder.clearInitialState()
is called, after which timeinitialStateMarked()
must returnfalse
. Also, during the time that the instance returnstrue
frominitialStateMarked()
, the implementation must return only the state that has changed in its implementation ofStateHolder.saveState(javax.faces.context.FacesContext)
.- Specified by:
markInitialState
in interfacePartialStateHolder
-
initialStateMarked
public boolean initialStateMarked()
Description copied from interface:PartialStateHolder
Return
true
if delta state changes are being tracked, otherwisefalse
- Specified by:
initialStateMarked
in interfacePartialStateHolder
-
clearInitialState
public void clearInitialState()
Description copied from interface:PartialStateHolder
Reset the PartialStateHolder to a non-delta tracking state.
- Specified by:
clearInitialState
in interfacePartialStateHolder
-
-
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 11/06/2005, zuletzt geändert 18/08/2025
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/java-api-javaee-rf-javax/faces/convert/EnumConverter.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.
Referenzen
Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor dieser Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.