Module org.apache.wicket.core
Class EnumChoiceRenderer<T extends Enum<T>>
java.lang.Object
org.apache.wicket.markup.html.form.EnumChoiceRenderer<T>
- Type Parameters:
T
-
- All Implemented Interfaces:
Serializable
,IChoiceRenderer<T>
,IDetachable
,IClusterable
IChoiceRenderer
implementation that makes it easy to work with java 5 enums. This
renderer will attempt to lookup strings used for the display value using a localizer of a given
component. If the component is not specified, the global instance of localizer will be used for
lookups.
display value resource key format: <enum.getSimpleClassName()>.<enum.name()>
id value format: <enum.name()>
- Author:
- igor.vaynberg
- See Also:
-
Constructor Summary
ConstructorDescriptionConstructor that creates the choice renderer that will use global instance of localizer to resolve resource keys.EnumChoiceRenderer
(Component resourceSource) Constructor -
Method Summary
Modifier and TypeMethodDescriptiongetDisplayValue
(T object) Get the value for displaying to an end user.getIdValue
(T object, int index) This method is called to get the id value of an object (used as the value attribute of a choice element) The id can be extracted from the object like a primary key, or if the list is stable you could just return a toString of the index.protected String
resourceKey
(T object) Translates theobject
into resource key that will be used to lookup the value shown to the userMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.wicket.markup.html.form.IChoiceRenderer
detach, getObject
-
Constructor Details
-
EnumChoiceRenderer
public EnumChoiceRenderer()Constructor that creates the choice renderer that will use global instance of localizer to resolve resource keys. -
EnumChoiceRenderer
Constructor- Parameters:
resourceSource
-
-
-
Method Details
-
getDisplayValue
Get the value for displaying to an end user.- Specified by:
getDisplayValue
in interfaceIChoiceRenderer<T extends Enum<T>>
- Parameters:
object
- the actual object- Returns:
- the value meant for displaying to an end user
-
resourceKey
Translates theobject
into resource key that will be used to lookup the value shown to the user- Parameters:
object
-- Returns:
- resource key
-
getIdValue
This method is called to get the id value of an object (used as the value attribute of a choice element) The id can be extracted from the object like a primary key, or if the list is stable you could just return a toString of the index.Note that the given index can be
-1
if the object in question is not contained in the available choices.- Specified by:
getIdValue
in interfaceIChoiceRenderer<T extends Enum<T>>
- Parameters:
object
- The object for which the id should be generatedindex
- The index of the object in the choices list.- Returns:
- String
-