Class SelectElement


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

    A SelectElement is used to create a drop-down list. OptionElement objects are used to define the available options in the list.

    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, OptionElement
    • Constructor Detail

      • SelectElement

        public SelectElement​(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
    • Method Detail

      • getCPtr

        public static long getCPtr​(SelectElement 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
      • makeFrom

        public static SelectElement makeFrom​(HtmlElement htmlElement)
        For internal use only. Of no interest to the user.
        Parameters:
        htmlElement - Internal use only
        Returns:
        a new SelectElement
      • getOptionElement

        public OptionElement getOptionElement​(java.lang.String value)
                                       throws NoSuchValueException,
                                              java.io.UnsupportedEncodingException
        Gets the OptionElement with the specified value. <option> tags don't contain a name attribute, they are distinguished by the text in their value attribute instead.
        Parameters:
        value - the value to look for
        Returns:
        the OptionElement with the specified value
        Throws:
        java.io.UnsupportedEncodingException - The encoding is not supported
        NoSuchValueException - no OptionElement with the specified value exists in this SelectElement
      • getOptionCount

        public int getOptionCount()
        Gets the number of OptionElement objects in this SelectElement.

        e.g.

        
         // iterate over the options within a SelectElement
         for (int i = 0; i < selectElement.getOptionCount(); i++)
         {
             OptionElement optionElement = selectElement.getOptionElement(i);
         }
         
        Returns:
        the number of options available in this SelectElement
        See Also:
        getOptionElement(int)
      • getOptionElement

        public OptionElement getOptionElement​(int index)
                                       throws NoSuchValueException
        Gets the OptionElement at the specifed index.

        e.g.

        
         // iterate over the options within a SelectElement
         for (int i = 0; i < selectElement.getOptionCount(); i++)
         {
             OptionElement optionElement = selectElement.getOptionElement(i);
         }
         
        Parameters:
        index - the index of the OptionElement to retrieve
        Returns:
        the OptionElement at the specifed index
        Throws:
        NoSuchValueException - the specified index is outside the available range
        See Also:
        getOptionCount()
      • isMultiple

        public boolean isMultiple()
        Returns true if it is possible to select multiple options at once.

        Calling this method is equivalent to checking if (getAttribute("multiple") == "multiple")

        Returns:
        true if multiple options can be selected at once
      • isSuccessfulControl

        public boolean isSuccessfulControl()
        Returns true if this SelectElement 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.

        A SelectElement is successful if getSelectedOption() returns an OptionElement.

        Overrides:
        isSuccessfulControl in class HtmlElement
        Returns:
        true if this SelectElement represents a successful control
      • 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
      • addOptionElement

        public void addOptionElement​(OptionElement element)
        Adds an OptionElement to the list of available OptionElement objects.

        The new option is added to the end of the list.

        Parameters:
        element - the OptionElement to add
      • insertOptionElement

        public void insertOptionElement​(int index,
                                        OptionElement element)
        Inserts an OptionElement into the list of available OptionElement objects.
        Parameters:
        index - the index at which to insert the option
        element - the OptionElement to insert
      • removeOptionElement

        public void removeOptionElement​(int index)
        Removes the OptionElement at the specified index from the list of available OptionElement objects.
        Parameters:
        index - the index in the list of the OptionElement to remove
      • removeOptionElement

        public void removeOptionElement​(java.lang.String value)
                                 throws java.io.UnsupportedEncodingException
        Removes the OptionElement with the specified value from the list of available OptionElement objects.
        Parameters:
        value - the value of the OptionElement to remove
        Throws:
        java.io.UnsupportedEncodingException - The encoding is not supported