Class AbstractSelect2Choice<T,M>

Type Parameters:
T - type of choice object
M - type of model object
All Implemented Interfaces:
Serializable, Iterable<Component>, IEventSink, IEventSource, IFeedbackContributor, IConverterLocator, IGenericComponent<M,FormComponent<M>>, IMetadataContext<Serializable,Component>, IRequestListener, IFormModelUpdateListener, IFormVisitorParticipant, ILabelProvider<String>, IHeaderContributor, IRequestableComponent, IHierarchical<Component>, IClusterable
Direct Known Subclasses:
Select2Choice, Select2MultiChoice

public abstract class AbstractSelect2Choice<T,M> extends FormComponent<M> implements IRequestListener
Base class for Select2 components
Author:
igor
See Also:
  • Constructor Details

    • AbstractSelect2Choice

      public AbstractSelect2Choice(String id)
      Parameters:
      id - markup id
    • AbstractSelect2Choice

      public AbstractSelect2Choice(String id, IModel<M> model)
      Constructor
      Parameters:
      id - component id
      model - component model
    • AbstractSelect2Choice

      public AbstractSelect2Choice(String id, ChoiceProvider<T> provider)
      Constructor.
      Parameters:
      id - component id
      provider - choice provider
    • AbstractSelect2Choice

      public AbstractSelect2Choice(String id, IModel<M> model, ChoiceProvider<T> provider)
      Construct.
      Parameters:
      id - markup id
      model - model for select
      provider - choice provider
  • Method Details

    • getSettings

      public final Settings getSettings()
      Returns the Settings. The settings
      closeOnSelect = true
      escapeMarkup = "Utils.escapeMarkup"
      width = Settings.Widths.RESOLVE;

      are the the Select2 default as documented on https://select2.org/configuration/options-api, which are different from the default in Settings
      Returns:
      Select2 settings for this component.
    • setProvider

      public final void setProvider(ChoiceProvider<T> provider)
      Sets the choice provider
      Parameters:
      provider - provider to set
    • getProvider

      public final ChoiceProvider<T> getProvider()
      Returns:
      choice provider
    • convertInput

      public final void convertInput()
      Overrides:
      convertInput in class FormComponent<M>
    • convertIdsToChoices

      protected final Collection<T> convertIdsToChoices(List<String> ids)
      Convert IDS into choices.
      Parameters:
      ids - list of identities
      Returns:
      collection of choices or empty collection
    • getJquerySafeMarkupId

      protected String getJquerySafeMarkupId()
      Gets the markup id that is safe to use in jQuery by escaping dots in the default Component.getMarkup()
      Returns:
      markup id
    • getEscapedJsString

      protected String getEscapedJsString(String key)
      Escapes single quotes in localized strings to be used as JavaScript strings enclosed in single quotes
      Parameters:
      key - resource key for localized message
      Returns:
      localized string with escaped single quotes
    • getCurrentValue

      protected final M getCurrentValue()
      Returns:
      current value, suitable for rendering as selected value in select2 component
    • onInitialize

      protected void onInitialize()
      Overrides:
      onInitialize in class MarkupContainer
    • onConfigure

      protected void onConfigure()
      Overrides:
      onConfigure in class Component
    • onEvent

      public void onEvent(IEvent<?> event)
      Specified by:
      onEvent in interface IEventSink
      Overrides:
      onEvent in class Component
    • getStatelessHint

      protected boolean getStatelessHint()
      Overrides:
      getStatelessHint in class Component
    • isAjax

      public boolean isAjax()
    • generateJSON

      public static <T> void generateJSON(ChoiceProvider<T> provider, OutputStream outputStream)
      Utility method to generate JSON response.
      Parameters:
      provider -
      outputStream -
    • generateJSON

      public static <T> void generateJSON(String queryParam, ChoiceProvider<T> provider, OutputStream outputStream)
      Utility method to generate JSON response.
      Parameters:
      provider -
      outputStream -
      queryParam - - parameter to be used as Ajax query param
    • onRequest

      public void onRequest()
      Specified by:
      onRequest in interface IRequestListener
    • onDetach

      protected void onDetach()
      Overrides:
      onDetach in class FormComponent<M>
    • appendOptionHtml

      protected void appendOptionHtml(AppendingStringBuffer buffer, T choice)
      Append a single option markup.
      Parameters:
      buffer - buffer to append to
      choice - choice to create option markup for
    • onComponentTag

      protected void onComponentTag(ComponentTag tag)
      Processes the component tag.
      Overrides:
      onComponentTag in class FormComponent<M>
      Parameters:
      tag - Tag to modify
      See Also:
    • onComponentTagBody

      public void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag)
      this method will add default options
      Overrides:
      onComponentTagBody in class MarkupContainer
      Parameters:
      markupStream - The markup stream
      openTag - The open tag for the body
    • createOptionsHtml

      protected abstract CharSequence createOptionsHtml(M currentValue)
      Creates the HTML option(s) markup representing the current value.
      Parameters:
      currentValue - the current value
      Returns:
      the HTML markup for any option(s)
    • isInputNullable

      public boolean isInputNullable()
      Empty input is acceptable
      Overrides:
      isInputNullable in class FormComponent<M>