Class Option


@Marshalled(typeName="option") public class Option extends HtmlElementText<Option>
DTO for an HTML <option> element.

The option element represents an option in a select element or a suggestion in a datalist element. It defines a choice that users can select from a dropdown menu or autocomplete list. The value attribute specifies the value to be submitted, while the text content provides the display text.

Examples:

import static org.apache.juneau.bean.html5.HtmlBuilder.*; // Simple option Option option1 = option("red", "Red"); // Selected option Option option2 = option("blue", "Blue") .selected(true); // Disabled option Option option3 = option("gray", "Gray") .disabled(true); // Option with label Option option4 = option("green", "Green") .label("Green Color"); // Options in a select Select select1 = select("color", option("red", "Red"), option("green", "Green"), option("blue", "Blue") );

The following convenience methods are provided for constructing instances of this bean:

See Also:
  • Constructor Details

  • Method Details

    • disabled

      public Option disabled(Object value)
      disabled attribute.

      Whether the form control is disabled.

      This attribute uses deminimized values:

      • false - Attribute is not added
      • true - Attribute is added as "disabled"
      • Other values - Passed through as-is
      Parameters:
      value - The new value for this attribute. Typically a Boolean or String. Can be null to unset the attribute.
      Returns:
      This object.
    • label

      public Option label(String value)
      label attribute.

      Specifies the user-visible label for the option. This label is displayed in the select element and can be different from the option's value.

      The label should be user-friendly and descriptive of what the option represents.

      Parameters:
      value - The user-visible label for the option. Can be null to unset the attribute.
      Returns:
      This object.
    • selected

      public Option selected(Object value)
      selected attribute.

      Whether the option is selected by default.

      This attribute uses deminimized values:

      • false - Attribute is not added
      • true - Attribute is added as "selected"
      • Other values - Passed through as-is
      Parameters:
      value - The new value for this attribute. Typically a Boolean or String. Can be null to unset the attribute.
      Returns:
      This object.
    • value

      public Option value(Object value)
      value attribute.

      Value to be used for form submission.

      Parameters:
      value - The new value for this attribute. Typically a Number or String. Can be null to unset the attribute.
      Returns:
      This object.