Package com.meterware.httpunit

# Class FormControl

java.lang.Object
com.meterware.httpunit.FormControl

All Implemented Interfaces:
  `HTMLElement`, `ScriptingEventHandler`

Direct Known Subclasses:
  `Button`, `RadioButtonFormControl`, `RadioGroupFormControl`

public abstract class FormControl extends Object
Represents a control in an HTML form.

Author:
  Russell Gold

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`class`
`FormControl.Scriptable`
implementation of Scriptable input elements

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`BUTTON_TYPE`
`static final String`
`CHECKBOX_TYPE`
`static final String`
`FILE_TYPE`
`static final String`
`HIDDEN_TYPE`
`static final String`
`IMAGE_BUTTON_TYPE`
`static final String`
`MULTIPLE_TYPE`
`static final String`
`PASSWORD_TYPE`
`static final String`
`RADIO_BUTTON_TYPE`
`static final String`
`RESET_BUTTON_TYPE`
`static final String`
`SINGLE_TYPE`
`static final String`
`SUBMIT_BUTTON_TYPE`
`static final String`
`TEXT_TYPE`
`static final String`
`TEXTAREA_TYPE`
`static final String`
`UNDEFINED_TYPE`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`FormControl(WebForm form, com.meterware.httpunit.dom.HTMLControl control)`
initialize the given form control from a Webform and a HTMLControl

## Method Summary

Modifier and Type
Method
Description
`protected abstract void`
`addValues(com.meterware.httpunit.protocol.ParameterProcessor processor, String characterSet)`
`protected void`
`claimUniqueValue(List values)`
Sets this control to the next compatible value from the list, removing it from the list.
`protected final void`
`claimValueIsRequired(List values, String value)`
Removes the specified required value from the list of values, throwing an exception if it is missing.
`boolean`
`doEvent(String eventScript)`
Deprecated.
since 1.7 - use doEventScript instead
`boolean`
`doEventScript(String eventScript)`
optional do the event if it's defined
`protected boolean`
`doOnChangeEvent()`
Performs the 'onchange' event defined for this control.
`protected boolean`
`doOnClickEvent()`
Performs the 'onClick' event defined for this control.
`protected boolean`
`doOnMouseDownEvent()`
Performs the 'onMouseDown' event defined for this control.
`protected boolean`
`doOnMouseUpEvent()`
Performs the 'onMouseUp' event defined for this control.
`protected String`
`emptyIfNull(String value)`
`String`
`getAttribute(String name)`
get the Attribute with the given name - by delegating to NodeUtils
`protected String`
`getAttribute(String name, String defaultValue)`
`String`
`getClassName()`
Returns the class associated with this element.
`protected String[]`
`getDisplayedOptions()`
Returns the list of values displayed by this control, if any.
`protected final WebForm`
`getForm()`
`String`
`getID()`
Returns the ID associated with this element.
`String`
`getName()`
Returns the name associated with this element.
`Node`
`getNode()`
Returns the DOM node underlying this element.
`String[]`
`getOptionValues()`
Returns the values permitted in this control.
`ScriptableDelegate`
`getParentDelegate()`
Returns the scriptable delegate which can provide the scriptable delegate for this element.
`ScriptingHandler`
`getScriptingHandler()`
Returns a scriptable object which can act as a proxy for this control.
`String`
`getTagName()`
Returns the tag name of this node.
`String`
`getText()`
Returns the text value of this block.
`String`
`getTitle()`
Returns the title associated with this element.
`abstract String`
`getType()`
Return the type of the control, as seen from JavaScript.
`protected String`
`getValueAttribute()`
Returns the value of this control in the form.
`protected abstract String[]`
`getValues()`
Returns the current value(s) associated with this control.
`boolean`
`handleEvent(String eventName)`
handle the event with the given name by getting the attribute and then executing the eventScript for it
`boolean`
`isDisabled()`
Returns true if this control is disabled, meaning that it will not send a value to the server as part of a request.
`boolean`
`isHidden()`
Returns true if this control is hidden.
`protected boolean`
`isMultiValued()`
Returns true if a single control can have multiple values.
`protected boolean`
`isReadOnly()`
Returns true if this control is read-only.
`boolean`
`isSupportedAttribute(String name)`
Returns true if this element may have an attribute with the specified name.
`ScriptableDelegate`
`newScriptable()`
Creates and returns a scriptable object for this control.
`void`
`removeAttribute(String name)`
remove the Attribute with the given name - by delegating to NodeUtils
`protected void`
`reset()`
Resets this control to its initial value.
`protected void`
`sendOnChangeEvent()`
Deprecated.
since 1.7 use doOnChangeEvent instead
`protected void`
`sendOnClickEvent()`
Deprecated.
since 1.7 use doOnClickEvent instead
`protected void`
`sendOnMouseDownEvent()`
Deprecated.
since 1.7 use doOnMouseDownEvent instead
`protected void`
`sendOnMouseUpEvent()`
Deprecated.
since 1.7 use doOnMouseUpEvent instead
`void`
`setAttribute(String name, Object value)`
set the Attribute with the given name - by delegating to NodeUtils
`void`
`setState(boolean state)`
Sets the state of this boolean control.
`protected void`
`setValueAttribute(String value)`
Sets the value of this control in the form.
`protected void`
`supportAttribute(String name)`
`void`
`toggle()`
Toggles the value of this control.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### UNDEFINED_TYPE

public static final String UNDEFINED_TYPE

See Also:
  - Constant Field Values

### BUTTON_TYPE

public static final String BUTTON_TYPE

See Also:
  - Constant Field Values

### RESET_BUTTON_TYPE

public static final String RESET_BUTTON_TYPE

See Also:
  - Constant Field Values

### SUBMIT_BUTTON_TYPE

public static final String SUBMIT_BUTTON_TYPE

See Also:
  - Constant Field Values

### IMAGE_BUTTON_TYPE

public static final String IMAGE_BUTTON_TYPE

See Also:
  - Constant Field Values

### RADIO_BUTTON_TYPE

public static final String RADIO_BUTTON_TYPE

See Also:
  - Constant Field Values

### CHECKBOX_TYPE

public static final String CHECKBOX_TYPE

See Also:
  - Constant Field Values

### TEXT_TYPE

public static final String TEXT_TYPE

See Also:
  - Constant Field Values

### PASSWORD_TYPE

public static final String PASSWORD_TYPE

See Also:
  - Constant Field Values

### HIDDEN_TYPE

public static final String HIDDEN_TYPE

See Also:
  - Constant Field Values

### TEXTAREA_TYPE

public static final String TEXTAREA_TYPE

See Also:
  - Constant Field Values

### FILE_TYPE

public static final String FILE_TYPE

See Also:
  - Constant Field Values

### SINGLE_TYPE

public static final String SINGLE_TYPE

See Also:
  - Constant Field Values

### MULTIPLE_TYPE

public static final String MULTIPLE_TYPE

See Also:
  - Constant Field Values

## Constructor Details

### FormControl

protected FormControl(WebForm form, com.meterware.httpunit.dom.HTMLControl control)
initialize the given form control from a Webform and a HTMLControl

Parameters:
  `form` -
  `control` -

## Method Details

### getType

public abstract String getType()
Return the type of the control, as seen from JavaScript.

### getValues

protected abstract String[] getValues()
Returns the current value(s) associated with this control. These values will be transmitted to the server if the control is 'successful'.

### getForm

protected final WebForm getForm()

### getParentDelegate

public ScriptableDelegate getParentDelegate()
Description copied from interface: `HTMLElement`
Returns the scriptable delegate which can provide the scriptable delegate for this element.

### getOptionValues

public String[] getOptionValues()
Returns the values permitted in this control. Does not apply to text or file controls.

### getDisplayedOptions

protected String[] getDisplayedOptions()
Returns the list of values displayed by this control, if any.

### isReadOnly

protected boolean isReadOnly()
Returns true if this control is read-only.

### isHidden

public boolean isHidden()
Returns true if this control is hidden.

### isDisabled

public boolean isDisabled()
Returns true if this control is disabled, meaning that it will not send a value to the server as part of a request.

### isMultiValued

protected boolean isMultiValued()
Returns true if a single control can have multiple values.

### addValues

protected abstract void addValues(com.meterware.httpunit.protocol.ParameterProcessor processor, String characterSet) throws IOException

Throws:
  `IOException`

### claimUniqueValue

protected void claimUniqueValue(List values)
Sets this control to the next compatible value from the list, removing it from the list.

### reset

protected void reset()
Resets this control to its initial value.

### toggle

public void toggle()
Toggles the value of this control.

### setState

public void setState(boolean state)
Sets the state of this boolean control.

### sendOnChangeEvent

protected void sendOnChangeEvent()
Deprecated.
since 1.7 use doOnChangeEvent instead
Performs the 'onChange' event defined for this control.

### doOnChangeEvent

protected boolean doOnChangeEvent()
Performs the 'onchange' event defined for this control.

### sendOnClickEvent

protected void sendOnClickEvent()
Deprecated.
since 1.7 use doOnClickEvent instead
Performs the 'onClick' event defined for this control.

### doOnClickEvent

protected boolean doOnClickEvent()
Performs the 'onClick' event defined for this control.

### sendOnMouseUpEvent

protected void sendOnMouseUpEvent()
Deprecated.
since 1.7 use doOnMouseUpEvent instead
Performs the 'onMouseUp' event defined for this control.

### doOnMouseUpEvent

protected boolean doOnMouseUpEvent()
Performs the 'onMouseUp' event defined for this control.

### sendOnMouseDownEvent

protected void sendOnMouseDownEvent()
Deprecated.
since 1.7 use doOnMouseDownEvent instead
Performs the 'onMouseDown' event defined for this control.

### doOnMouseDownEvent

protected boolean doOnMouseDownEvent()
Performs the 'onMouseDown' event defined for this control.

### newScriptable

public ScriptableDelegate newScriptable()
Creates and returns a scriptable object for this control. Subclasses should override this if they use a different implementation of Scriptable.

Specified by:
  `newScriptable` in interface `HTMLElement`

### getValueAttribute

protected String getValueAttribute()
Returns the value of this control in the form. If no value is specified, defaults to the empty string.

### setValueAttribute

protected void setValueAttribute(String value)
Sets the value of this control in the form.

### claimValueIsRequired

protected final void claimValueIsRequired(List values, String value)
Removes the specified required value from the list of values, throwing an exception if it is missing.

### emptyIfNull

protected String emptyIfNull(String value)

### getID

public String getID()
Description copied from interface: `HTMLElement`
Returns the ID associated with this element. IDs are unique throughout the HTML document.

Specified by:
  `getID` in interface `HTMLElement`

### getClassName

public String getClassName()
Description copied from interface: `HTMLElement`
Returns the class associated with this element.

Specified by:
  `getClassName` in interface `HTMLElement`

### getTitle

public String getTitle()
Description copied from interface: `HTMLElement`
Returns the title associated with this element.

Specified by:
  `getTitle` in interface `HTMLElement`

### getName

public String getName()
Description copied from interface: `HTMLElement`
Returns the name associated with this element.

Specified by:
  `getName` in interface `HTMLElement`

### getScriptingHandler

public ScriptingHandler getScriptingHandler()
Returns a scriptable object which can act as a proxy for this control.

Specified by:
  `getScriptingHandler` in interface `HTMLElement`

### doEvent

public boolean doEvent(String eventScript)
Deprecated.
since 1.7 - use doEventScript instead
handle the event that has the given script attached by compiling the eventScript as a function and executing it

Specified by:
  `doEvent` in interface `ScriptingEventHandler`
Parameters:
  `eventScript` - - the script to use
Returns:
  true if the script is empty or the result of the script

### doEventScript

public boolean doEventScript(String eventScript)
optional do the event if it's defined

Specified by:
  `doEventScript` in interface `ScriptingEventHandler`
Parameters:
  `eventScript` -
Returns:
  true if the script is empty or the result of the script

### handleEvent

public boolean handleEvent(String eventName)
Description copied from interface: `ScriptingEventHandler`
handle the event with the given name by getting the attribute and then executing the eventScript for it

Specified by:
  `handleEvent` in interface `ScriptingEventHandler`
Parameters:
  `eventName` -
Returns:
  the result of doEventScript

### getText

public String getText()
Returns the text value of this block.

Specified by:
  `getText` in interface `HTMLElement`

### getTagName

public String getTagName()
Description copied from interface: `HTMLElement`
Returns the tag name of this node.

Specified by:
  `getTagName` in interface `HTMLElement`

### getAttribute

public String getAttribute(String name)
get the Attribute with the given name - by delegating to NodeUtils

Specified by:
  `getAttribute` in interface `HTMLElement`
Parameters:
  `name` - - the name of the attribute to get
Returns:
  the attribute

### setAttribute

public void setAttribute(String name, Object value)
set the Attribute with the given name - by delegating to NodeUtils

Specified by:
  `setAttribute` in interface `HTMLElement`
Parameters:
  `name` - - the name of the attribute to set
  `value` - - the value to set

### removeAttribute

public void removeAttribute(String name)
remove the Attribute with the given name - by delegating to NodeUtils

Specified by:
  `removeAttribute` in interface `HTMLElement`
Parameters:
  `name` - - the name of the attribute to remove

### isSupportedAttribute

public boolean isSupportedAttribute(String name)
Description copied from interface: `HTMLElement`
Returns true if this element may have an attribute with the specified name.

Specified by:
  `isSupportedAttribute` in interface `HTMLElement`

### getAttribute

protected String getAttribute(String name, String defaultValue)

### getNode

public Node getNode()
Description copied from interface: `HTMLElement`
Returns the DOM node underlying this element.

Specified by:
  `getNode` in interface `HTMLElement`

### supportAttribute

protected void supportAttribute(String name)