Class AbstractChoice<T,E>

Type Parameters:
T - The model object type
E - class of a single element in the choices list
All Implemented Interfaces:
Serializable, Iterable<Component>, IEventSink, IEventSource, IFeedbackContributor, IConverterLocator, IGenericComponent<T,FormComponent<T>>, IMetadataContext<Serializable,Component>, IFormModelUpdateListener, IFormVisitorParticipant, ILabelProvider<String>, IHeaderContributor, IRequestableComponent, IHierarchical<Component>, IClusterable
Direct Known Subclasses:
AbstractSingleSelectChoice, ListMultipleChoice

public abstract class AbstractChoice<T,E> extends FormComponent<T>
Abstract base class for all choice (html select) options.

This component uses String concatenation to keep its memory footprint light. Use Select, SelectOptions and SelectOption from wicket-extensions for more sophisticated needs.

Author:
Jonathan Locke, Eelco Hillenius, Johan Compagner
See Also:
  • Constructor Details

    • AbstractChoice

      public AbstractChoice(String id)
      Constructor.
      Parameters:
      id - See Component
    • AbstractChoice

      public AbstractChoice(String id, List<? extends E> choices)
      Constructor.
      Parameters:
      id - See Component
      choices - The collection of choices in the dropdown
    • AbstractChoice

      public AbstractChoice(String id, List<? extends E> choices, IChoiceRenderer<? super E> renderer)
      Constructor.
      Parameters:
      id - See Component
      renderer - The rendering engine
      choices - The collection of choices in the dropdown
    • AbstractChoice

      public AbstractChoice(String id, IModel<T> model, List<? extends E> choices)
      Constructor.
      Parameters:
      id - See Component
      model - See Component
      choices - The collection of choices in the dropdown
    • AbstractChoice

      public AbstractChoice(String id, IModel<T> model, List<? extends E> choices, IChoiceRenderer<? super E> renderer)
      Constructor.
      Parameters:
      id - See Component
      model - See Component
      choices - The drop down choices
      renderer - The rendering engine
    • AbstractChoice

      public AbstractChoice(String id, IModel<? extends List<? extends E>> choices)
      Constructor.
      Parameters:
      id - See Component
      choices - The collection of choices in the dropdown
    • AbstractChoice

      public AbstractChoice(String id, IModel<? extends List<? extends E>> choices, IChoiceRenderer<? super E> renderer)
      Constructor.
      Parameters:
      id - See Component
      renderer - The rendering engine
      choices - The collection of choices in the dropdown
    • AbstractChoice

      public AbstractChoice(String id, IModel<T> model, IModel<? extends List<? extends E>> choices)
      Constructor.
      Parameters:
      id - See Component
      model - See Component
      choices - The collection of choices in the dropdown
    • AbstractChoice

      public AbstractChoice(String id, IModel<T> model, IModel<? extends List<? extends E>> choices, IChoiceRenderer<? super E> renderer)
      Constructor.
      Parameters:
      id - See Component
      model - See Component
      renderer - The rendering engine
      choices - The drop down choices
  • Method Details

    • getChoices

      public final List<? extends E> getChoices()
      Returns:
      The collection of object that this choice has
    • getChoicesModel

      public IModel<? extends List<? extends E>> getChoicesModel()
      Returns:
      The model with the choices for this component
    • setChoices

      public final AbstractChoice<T,E> setChoices(IModel<? extends List<? extends E>> choices)
      Sets the list of choices
      Parameters:
      choices - model representing the list of choices
      Returns:
      this for chaining
    • setChoices

      public final AbstractChoice<T,E> setChoices(List<? extends E> choices)
      Sets the list of choices.
      Parameters:
      choices - the list of choices
      Returns:
      this for chaining
    • getChoiceRenderer

      public final IChoiceRenderer<? super E> getChoiceRenderer()
      Returns:
      The IChoiceRenderer used for rendering the data objects
    • setChoiceRenderer

      public final AbstractChoice<T,E> setChoiceRenderer(IChoiceRenderer<? super E> renderer)
      Set the choice renderer to be used.
      Parameters:
      renderer - The IChoiceRenderer used for rendering the data objects
      Returns:
      this for chaining
    • detachModel

      protected void detachModel()
      Description copied from class: Component
      Detaches the model for this component if it is detachable.
      Overrides:
      detachModel in class Component
    • getDefaultChoice

      protected CharSequence getDefaultChoice(String selectedValue)
      Get a default choice to be rendered additionally to the choices available in the model.
      Parameters:
      selectedValue - The currently selected value
      Returns:
      Any default choice, such as "Choose One", depending on the subclass
      See Also:
    • isSelected

      protected abstract boolean isSelected(E object, int index, String selected)
      Gets whether the given value represents the current selection.
      Parameters:
      object - The object to check
      index - The index in the choices collection this object is in.
      selected - The currently selected string value
      Returns:
      Whether the given value represents the current selection
    • isDisabled

      protected boolean isDisabled(E object, int index, String selected)
      Gets whether the given value is disabled. This default implementation always returns false.
      Parameters:
      object - The object to check
      index - The index in the choices collection this object is in.
      selected - The currently selected string value
      Returns:
      Whether the given value represents the current selection
    • onComponentTagBody

      public void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag)
      Handle the container's body.
      Overrides:
      onComponentTagBody in class MarkupContainer
      Parameters:
      markupStream - The markup stream
      openTag - The open tag for the body
    • appendOptionHtml

      protected void appendOptionHtml(AppendingStringBuffer buffer, E choice, int index, String selected)
      Generates and appends html for a single choice into the provided buffer
      Parameters:
      buffer - Appending string buffer that will have the generated html appended
      choice - Choice object
      index - The index of this option
      selected - The currently selected string value
    • setOptionAttributes

      protected void setOptionAttributes(AppendingStringBuffer buffer, E choice, int index, String selected)
      Sets the attributes of a single choice into the provided buffer.
      Parameters:
      buffer - Appending string buffer that will have the generated html appended
      choice - Choice object
      index - The index of this option
      selected - The currently selected string value
    • escapeOptionHtml

      protected CharSequence escapeOptionHtml(String displayValue)
      Method to override if you want special escaping of the options html.
      Parameters:
      displayValue -
      Returns:
      The escaped display value
    • localizeDisplayValues

      protected boolean localizeDisplayValues()
      Override this method if you want to localize the display values of the generated options. By default false is returned so that the display values of options are not tested if they have a i18n key.
      Returns:
      true If you want to localize the display values, default == false
    • setType

      public final FormComponent<T> setType(Class<?> type)
      Description copied from class: FormComponent
      Sets the type that will be used when updating the model for this component. If no type is specified String type is assumed.
      Overrides:
      setType in class FormComponent<T>
      Returns:
      this for chaining
    • onDetach

      protected void onDetach()
      Description copied from class: FormComponent
      Sets the temporary converted input value to null.
      Overrides:
      onDetach in class FormComponent<T>
      See Also: