Class HTMLOptionsCollection

java.lang.Object
org.htmlunit.corejs.javascript.ScriptableObject
org.htmlunit.javascript.HtmlUnitScriptable
org.htmlunit.javascript.host.html.HTMLOptionsCollection
All Implemented Interfaces:
Serializable, Cloneable, org.htmlunit.corejs.javascript.ConstProperties, org.htmlunit.corejs.javascript.debug.DebuggableObject, org.htmlunit.corejs.javascript.Scriptable, org.htmlunit.corejs.javascript.SymbolScriptable

public class HTMLOptionsCollection extends HtmlUnitScriptable
This is the array returned by the "options" property of Select.
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.htmlunit.corejs.javascript.ScriptableObject

    org.htmlunit.corejs.javascript.ScriptableObject.KeyComparator
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private HtmlSelect
     

    Fields inherited from class org.htmlunit.corejs.javascript.ScriptableObject

    CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST

    Fields inherited from interface org.htmlunit.corejs.javascript.Scriptable

    NOT_FOUND
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an instance.
    Creates an instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(Object newOptionObject, Object beforeOptionObject)
    Adds a new item to the option collection.
    get(int index, org.htmlunit.corejs.javascript.Scriptable start)
    Returns the object at the specified index.
    int
    Returns the number of elements in this array.
    int
    Returns the value of the selectedIndex property.
    void
    Initializes this object.
    item(int index)
    Returns the object at the specified index.
    org.htmlunit.corejs.javascript.Scriptable
     
    void
    JavaScript constructor.
    void
    put(int index, org.htmlunit.corejs.javascript.Scriptable start, Object newValue)
    Sets the index property.
    void
    put(String name, org.htmlunit.corejs.javascript.Scriptable start, Object value)
    void
    remove(int index)
    Removes the option at the specified index.
    void
    setLength(int newLength)
    Changes the number of options: removes options if the new length is less than the current one else add new empty options to reach the new length.
    void
    setSelectedIndex(int index)
    Sets the value of the selectedIndex property.

    Methods inherited from class org.htmlunit.corejs.javascript.ScriptableObject

    applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, delete, deleteProperty, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureSymbolScriptable, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, putConst, putConstProperty, putProperty, putProperty, putProperty, querySlot, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setAttributes, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setPrototype, size

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • HTMLOptionsCollection

      public HTMLOptionsCollection()
      Creates an instance.
    • HTMLOptionsCollection

      public HTMLOptionsCollection(HtmlUnitScriptable parentScope)
      Creates an instance.
      Parameters:
      parentScope - parent scope
  • Method Details

    • jsConstructor

      public void jsConstructor()
      JavaScript constructor.
    • initialize

      public void initialize(HtmlSelect select)
      Initializes this object.
      Parameters:
      select - the HtmlSelect that this object will retrieve elements from
    • get

      public Object get(int index, org.htmlunit.corejs.javascript.Scriptable start)
      Returns the object at the specified index.
      Specified by:
      get in interface org.htmlunit.corejs.javascript.Scriptable
      Overrides:
      get in class org.htmlunit.corejs.javascript.ScriptableObject
      Parameters:
      index - the index
      start - the object that get is being called on
      Returns:
      the object or NOT_FOUND
    • put

      public void put(String name, org.htmlunit.corejs.javascript.Scriptable start, Object value)
      Specified by:
      put in interface org.htmlunit.corejs.javascript.Scriptable
      Overrides:
      put in class HtmlUnitScriptable
    • item

      public Object item(int index)
      Returns the object at the specified index.
      Parameters:
      index - the index
      Returns:
      the object or NOT_FOUND
    • put

      public void put(int index, org.htmlunit.corejs.javascript.Scriptable start, Object newValue)
      Sets the index property.
      Specified by:
      put in interface org.htmlunit.corejs.javascript.Scriptable
      Overrides:
      put in class org.htmlunit.corejs.javascript.ScriptableObject
      Parameters:
      index - the index
      start - the scriptable object that was originally invoked for this property
      newValue - the new value
    • getLength

      public int getLength()
      Returns the number of elements in this array.
      Returns:
      the number of elements in the array
    • setLength

      public void setLength(int newLength)
      Changes the number of options: removes options if the new length is less than the current one else add new empty options to reach the new length.
      Parameters:
      newLength - the new length property value
    • add

      public void add(Object newOptionObject, Object beforeOptionObject)
      Adds a new item to the option collection.

      Implementation Note: The specification for the JavaScript add() method actually calls for the optional newIndex parameter to be an integer. However, the newIndex parameter is specified as an Object here rather than an int because of the way Rhino and HtmlUnit process optional parameters for the JavaScript method calls. If the newIndex parameter were specified as an int, then the Undefined value for an integer is specified as NaN (Not A Number, which is a Double value), but Rhino translates this value into 0 (perhaps correctly?) when converting NaN into an int. As a result, when the newIndex parameter is not specified, it is impossible to make a distinction between a caller of the form add(someObject) and add (someObject, 0). Since the behavior of these two call forms is different, the newIndex parameter is specified as an Object. If the newIndex parameter is not specified by the actual JavaScript code being run, then newIndex is of type org.htmlunit.corejs.javascript.Undefined. If the newIndex parameter is specified, then it should be of type java.lang.Number and can be converted into an integer value.

      This method will call the put(int, Scriptable, Object) method for actually adding the element to the collection.

      According to the Microsoft DHTML reference page for the JavaScript add() method of the options collection, the index parameter is specified as follows:

      Optional. Integer that specifies the index position in the collection where the element is placed. If no value is given, the method places the element at the end of the collection.

      Parameters:
      newOptionObject - the DomNode to insert in the collection
      beforeOptionObject - An optional parameter which specifies the index position in the collection where the element is placed. If no value is given, the method places the element at the end of the collection.
      See Also:
    • remove

      public void remove(int index)
      Removes the option at the specified index.
      Parameters:
      index - the option index
    • getSelectedIndex

      public int getSelectedIndex()
      Returns the value of the selectedIndex property.
      Returns:
      the selectedIndex property
    • setSelectedIndex

      public void setSelectedIndex(int index)
      Sets the value of the selectedIndex property.
      Parameters:
      index - the new value
    • iterator

      public org.htmlunit.corejs.javascript.Scriptable iterator()