Class AbstractSingleSelectChoice<T>

Type Parameters:
T - The model object type
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:
DropDownChoice, RadioChoice

public abstract class AbstractSingleSelectChoice<T> extends AbstractChoice<T,T>
Abstract base class for single-select choices.
Author:
Jonathan Locke, Eelco Hillenius nm, Johan Compagner
See Also:
  • Constructor Details

  • Method Details

    • getModelValue

      Overrides:
      getModelValue in class FormComponent<T>
      Returns:
      Value to return when model value is needed
      See Also:
    • isNullValid

      public boolean isNullValid()
      Determines whether or not the null value should be included in the list of choices when the field's model value is nonnull, and whether or not the null_valid string property (e.g. "Choose One") should be displayed until a nonnull value is selected. If set to false, then "Choose One" will be displayed when the value is null. After a value is selected, and that change is propagated to the underlying model, the user will no longer see the "Choose One" option, and there will be no way to reselect null as the value. If set to true, the null string property (the empty string, by default) will always be displayed as an option, whether or not a nonnull value has ever been selected. Note that this setting has no effect on validation; in order to guarantee that a value will be specified on form validation, FormComponent.setRequired(boolean). This is because even if setNullValid() is called with false, the user can fail to provide a value simply by never activating (i.e. clicking on) the component.
      Returns:
      true when the null value is allowed.
    • setNullValid

      public AbstractSingleSelectChoice<T> setNullValid(boolean nullValid)
      Determines whether or not the null value should be included in the list of choices when the field's model value is nonnull, and whether or not the null_valid string property (e.g. "Choose One") should be displayed until a nonnull value is selected. If set to false, then "Choose One" will be displayed when the value is null. After a value is selected, and that change is propagated to the underlying model, the user will no longer see the "Choose One" option, and there will be no way to reselect null as the value. If set to true, the null string property (the empty string, by default) will always be displayed as an option, whether or not a nonnull value has ever been selected. Note that this setting has no effect on validation; in order to guarantee that a value will be specified on form validation, FormComponent.setRequired(boolean). This is because even if setNullValid() is called with false, the user can fail to provide a value simply by never activating (i.e. clicking on) the component.
      Parameters:
      nullValid - whether null is a valid value
      Returns:
      this for chaining
    • convertValue

      protected final T convertValue(String[] value)
      Description copied from class: FormComponent
      Subclasses should overwrite this if the conversion is not done through the type field and the IConverter. WARNING: this method may be removed in future versions. If conversion fails then a ConversionException should be thrown
      Overrides:
      convertValue in class FormComponent<T>
      Parameters:
      value - The value can be the getInput() or through a cookie
      Returns:
      The converted value. default returns just the given value
      See Also:
    • convertChoiceIdToChoice

      Converts submitted choice id string back to choice object.
      Parameters:
      id - string id of one of the choice objects in the choices list. can be null.
      Returns:
      choice object. null if none match the specified id.
    • getDefaultChoice

      protected CharSequence getDefaultChoice(String selectedValue)
      Asks the Localizer for the property to display for an additional default choice depending on isNullValid():
      • "nullValid" if null is valid, defaulting to an empty string.
      • "null" if null is not valid but no choice is selected (i.e. selectedValue is empty), defaulting to "Choose one".
      Otherwise no additional default choice will be returned.
      Overrides:
      getDefaultChoice in class AbstractChoice<T,T>
      Parameters:
      selectedValue - The currently selected value
      Returns:
      Any default choice, such as "Choose One", depending on the subclass
      See Also:
    • getNullValidDisplayValue

      Returns the display value for the null value. The default behavior is to look the value up by using the key from getNullValidKey().
      Returns:
      The value to display for null
    • getNullValidKey

      protected String getNullValidKey()
      Return the localization key for nullValid value
      Returns:
      getId() + ".nullValid"
    • getNullKeyDisplayValue

      Returns the display value if null is not valid but is selected. The default behavior is to look the value up by using the key from getNullKey().
      Returns:
      The value to display if null is not value but selected, e.g. "Choose One"
    • getNullKey

      protected String getNullKey()
      Return the localization key for null value
      Returns:
      getId() + ".null"
    • isSelected

      protected boolean isSelected(T object, int index, String selected)
      Gets whether the given value represents the current selection.
      Specified by:
      isSelected in class AbstractChoice<T,T>
      Parameters:
      object - The object to check
      index - The index of the object in the collection
      selected - The current selected id value
      Returns:
      Whether the given value represents the current selection