Class AbstractChoice<T,​E>

    • Constructor Detail

      • 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 Detail

      • getChoices

        public final List<? extends EgetChoices()
        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,​EsetChoices​(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,​EsetChoices​(List<? extends E> choices)
        Sets the list of choices.
        Parameters:
        choices - the list of choices
        Returns:
        this for chaining
      • setChoiceRenderer

        public final AbstractChoice<T,​EsetChoiceRenderer​(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
      • 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:
        setChoices(IModel)
      • 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
      • 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<TsetType​(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