Class OptionElement


  • public class OptionElement
    extends HtmlElement
    Represents an HTML option element within an HTML form. An HTML element is everything from the start tag to the end tag.

    An OptionElement is used to define an available option in a drop-down list represented by a SelectElement.

    e.g.

    
     <select name="drink">
         <option value="lemonade">Lemonade</option>
         <option value="coke">Coke</option>
         <option value="pepsi">Pepsi</option>
         <option value="tango">Tango</option>
     </select>
     
    When the containing Form is sent to the web server, a name/value pair will be sent which uses the name of the SelectElement and the value of the currently selected OptionElement.
    See Also:
    Form, SelectElement, SelectElement.setSelectedOption(OptionElement)
    • Constructor Detail

      • OptionElement

        public OptionElement​(long cPtr,
                             boolean cMemoryOwn)
        For internal use only. Of no interest to the user.
        Parameters:
        cPtr - pointer to the CPP wrapped object
        cMemoryOwn - indicates if this object is responsible for memory management of the CPP object
      • OptionElement

        public OptionElement​(java.lang.String value)
                      throws java.io.UnsupportedEncodingException
        Creates a new OptionElement object with the specified value.
        Parameters:
        value - the value of the option
        Throws:
        java.io.UnsupportedEncodingException - The encoding is not supported
    • Method Detail

      • getCPtr

        public static long getCPtr​(OptionElement obj)
        For internal use only. Of no interest to the user.
        Parameters:
        obj - a reference to an object of this class
        Returns:
        a long containing the address of the CPP wrapped object
      • selected

        public boolean selected()
        Returns true if this OptionElement has been selected. An OptionElement is selected if it has a "selected" attribute, i.e. if hasAttribute("selected") returns true.
        Returns:
        true if this option has been selected
        See Also:
        setSelected(boolean)
      • setSelected

        public void setSelected​(boolean selected)
        Sets or removes the "selected" attribute for this OptionElement.

        setSelected(true) is equivalent to setAttribute("selected").

        setSelected(false) is equivalent to removeAttribute("selected").

        Parameters:
        selected - true to select the OptionElement, false to de-select it
        See Also:
        selected(), isSuccessfulControl()
      • isSuccessfulControl

        public boolean isSuccessfulControl()
        Returns true if this OptionElement currently represents a successful control. A successful control is one that is valid for submission, i.e. one that will be sent to the web server when the form is submitted.

        An OptionElement is successful if it has been selected().

        Overrides:
        isSuccessfulControl in class HtmlElement
        Returns:
        true if this OptionElement represents a successful control
        See Also:
        setSelected(boolean), selected()
      • clone

        public HtmlElement clone()
        Description copied from class: HtmlElement
        Creates a copy of this HTML element.
        Overrides:
        clone in class HtmlElement
        Returns:
        a new HtmlElement object which is an exact copy of this HTML element