Class Select


@Marshalled(typeName="select") public class Select extends HtmlElementContainer<Select>
DTO for an HTML <select> element.

The select element represents a control that provides a menu of options. It creates a dropdown list that allows users to select one or more options from a list. The select element contains option elements that define the available choices, and can be organized into groups using optgroup elements.

Examples:

import static org.apache.juneau.bean.html5.HtmlBuilder.*; // Simple select dropdown Select select1 = select("color", option("red", "Red"), option("green", "Green"), option("blue", "Blue") ); // Multiple selection Select select2 = select("hobbies", option("reading", "Reading"), option("gaming", "Gaming"), option("sports", "Sports") ).multiple(true).size(4); // Select with option groups Select select3 = select("food", optgroup("Fruits", option("apple", "Apple"), option("banana", "Banana") ), optgroup("Vegetables", option("carrot", "Carrot"), option("broccoli", "Broccoli") ) ); // Disabled select Select select4 = select("disabled") .disabled(true) .children( option().value("option1").text("Option 1") );

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

See Also:
  • Constructor Details

    • Select

      public Select()
      Creates an empty Select element.
    • Select

      public Select(String name, Object... children)
      Creates a Select element with the specified name(String) attribute and child nodes.
      Parameters:
      name - The name(String) attribute. Can be null to unset the attribute.
      children - The child nodes. Must not be null.
  • Method Details

    • autofocus

      public Select autofocus(Object value)
      autofocus attribute.

      Automatically focus the form control when the page is loaded.

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

      public Select choose(Object optionValue)
      Convenience method for selecting a child Option after the options have already been populated.
      Parameters:
      optionValue - The option value. Can be null (no-op; no option is selected).
      Returns:
      This object.
    • disabled

      public Select 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.
    • form

      public Select form(String value)
      form attribute.

      Associates the select element with a form element by specifying the form's ID. This allows the select to be placed outside the form element while still being part of the form.

      The value should match the ID of a form element in the same document.

      Parameters:
      value - The ID of the form element to associate with this select. Can be null to unset the attribute.
      Returns:
      This object.
    • multiple

      public Select multiple(Object value)
      multiple attribute.

      Whether to allow multiple values.

      This attribute uses deminimized values:

      • false - Attribute is not added
      • true - Attribute is added as "multiple"
      • 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.
    • name

      public Select name(String value)
      name attribute.

      Specifies the name of the select element. This name is used when the form is submitted and can be used to access the element via the form.elements API.

      The name should be unique within the form and should not contain spaces or special characters.

      Parameters:
      value - The name of the select element for submission and API access. Can be null to unset the attribute.
      Returns:
      This object.
    • required

      public Select required(Object value)
      required attribute.

      Whether the control is required for form submission.

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

      public Select size(Object value)
      size attribute.

      Specifies the number of visible options in a select element. If greater than 1, the select becomes a scrollable list instead of a dropdown.

      Parameters:
      value - The number of visible options (1 for dropdown, >1 for list). Can be null to unset the attribute.
      Returns:
      This object.