Class AbstractSingleSelectChoice<T>

    • Method Detail

      • 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<TsetNullValid​(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:
        FormComponent.convertValue(String[])
      • convertChoiceIdToChoice

        protected T convertChoiceIdToChoice​(String id)
        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.
      • getNullValidDisplayValue

        protected String 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

        protected String 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