Interface IChoiceRenderer<T>

Type Parameters:
T - The model object type
All Superinterfaces:
IClusterable, IDetachable, Serializable
All Known Implementing Classes:
ChoiceRenderer, EnumChoiceRenderer, LambdaChoiceRenderer

public interface IChoiceRenderer<T> extends IDetachable
Renders one choice. Separates the 'id' values used for internal representation from 'display values' which are the values shown to the user of components that use this renderer.
Author:
jcompagner
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Override when needed.
    Get the value for displaying to an end user.
    default 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.
    default T
    getObject(String id, IModel<? extends List<? extends T>> choices)
    This method is called to get an object back from its id representation.
  • Method Details

    • getDisplayValue

      Get the value for displaying to an end user.
      Parameters:
      object - the actual object
      Returns:
      the value meant for displaying to an end user
    • getIdValue

      default 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.

      Parameters:
      object - The object for which the id should be generated
      index - The index of the object in the choices list.
      Returns:
      String
    • getObject

      default T getObject(String id, IModel<? extends List<? extends T>> choices)
      This method is called to get an object back from its id representation. The id may be used to find/load the object in a more efficient way than loading all choices and find the one with the same id in the list
      Parameters:
      id - The id representation of the object
      choices - The list of all rendered choices
      Returns:
      A choice from the list that has this id
    • detach

      default void detach()
      Override when needed.
      Specified by:
      detach in interface IDetachable