Class EnumChoiceRenderer<T extends Enum<T>>

  • Type Parameters:
    T -
    All Implemented Interfaces:
    Serializable, IChoiceRenderer<T>, IDetachable, IClusterable

    public class EnumChoiceRenderer<T extends Enum<T>>
    extends ChoiceRenderer<T>
    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()>.<>

    id value format: <>

    See Also:
    Serialized Form
    • Constructor Detail

      • EnumChoiceRenderer

        public EnumChoiceRenderer()
        Constructor that creates the choice renderer that will use global instance of localizer to resolve resource keys.
    • Method Detail

      • resourceKey

        protected String resourceKey​(T object)
        Translates the object into resource key that will be used to lookup the value shown to the user
        object -
        resource key
      • getIdValue

        public String 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.

        Note that the given index can be -1 if the object in question is not contained in the available choices.

        Specified by:
        getIdValue in interface IChoiceRenderer<T extends Enum<T>>
        getIdValue in class ChoiceRenderer<T extends Enum<T>>
        object - The object for which the id should be generated
        index - The index of the object in the choices list.