Class HtmlForm

All Implemented Interfaces:
Serializable, Cloneable, Element, Node

public class HtmlForm extends HtmlElement
Wrapper for the HTML element "form".
See Also:
  • Field Details

    • TAG_NAME

      public static final String TAG_NAME
      The HTML tag represented by this element.
      See Also:
    • ATTRIBUTE_FORMNOVALIDATE

      public static final String ATTRIBUTE_FORMNOVALIDATE
      The "formnovalidate" attribute name.
      See Also:
  • Method Details

    • submit

      public void submit(SubmittableElement submitElement)
      INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.

      Submits this form to the server. If submitElement is null, then the submission is treated as if it was triggered by JavaScript, and the onsubmit handler will not be executed.

      IMPORTANT: Using this method directly is not the preferred way of submitting forms. Most consumers should emulate the user's actions instead, probably by using something like DomElement.click() or DomElement.dblClick().

      Parameters:
      submitElement - the element that caused the submit to occur
    • getWebRequest

      public WebRequest getWebRequest(SubmittableElement submitElement)
      INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
      Gets the request for a submission of this form with the specified SubmittableElement.
      Parameters:
      submitElement - the element that caused the submit to occur
      Returns:
      the request
    • getParameterListForSubmit

      public List<NameValuePair> getParameterListForSubmit(SubmittableElement submitElement)
      INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
      Returns a list of NameValuePairs that represent the data that will be sent to the server when this form is submitted. This is primarily intended to aid debugging.
      Parameters:
      submitElement - the element used to submit the form, or null if the form was submitted by JavaScript
      Returns:
      the list of NameValuePairs that represent that data that will be sent to the server when this form is submitted
    • reset

      public Page reset()
      Resets this form to its initial values, returning the page contained by this form's window after the reset. Note that the returned page may or may not be the same as the original page, based on JavaScript event handlers, etc.
      Returns:
      the page contained by this form's window after the reset
    • isValid

      public boolean isValid()
      Returns whether this element satisfies all form validation constraints set.
      Overrides:
      isValid in class HtmlElement
      Returns:
      whether this element satisfies all form validation constraints set
    • getInputsByName

      public List<HtmlInput> getInputsByName(String name)
      Returns all input elements which are members of this form and have the specified name.
      Parameters:
      name - the input name to search for
      Returns:
      all input elements which are members of this form and have the specified name
    • getElements

      @Deprecated public List<HtmlElement> getElements()
      Deprecated.
      as of version 4.4.0; use getFormElements(), getElementsJS() instead
      Returns:
      returns a list of all form controls contained in the <form> element or referenced by formId but ignoring elements that are contained in a nested form
    • getFormElements

      public List<HtmlElement> getFormElements()
      Returns:
      A List containing all form controls in the form. The form controls in the returned collection are in the same order in which they appear in the form by following a preorder, depth-first traversal of the tree. This is called tree order. Only the following elements are returned: button, fieldset, input, object, output, select, textarea.
    • getElementsJS

      public List<HtmlElement> getElementsJS()
      This is the backend for the getElements() javascript function of the form. see https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/elements
      Returns:
      A List containing all non-image controls in the form. The form controls in the returned collection are in the same order in which they appear in the form by following a preorder, depth-first traversal of the tree. This is called tree order. Only the following elements are returned: button, fieldset, input (with the exception that any whose type is "image" are omitted for historical reasons), object, output, select, textarea.
    • getElements

      public List<HtmlElement> getElements(Predicate<HtmlElement> filter)
      Parameters:
      filter - a predicate to filter the element
      Returns:
      all elements attached to this form and matching the filter predicate
    • getInputByName

      public final <I extends HtmlInput> I getInputByName(String name) throws ElementNotFoundException
      Returns the first input element which is a member of this form and has the specified name.
      Type Parameters:
      I - the input type
      Parameters:
      name - the input name to search for
      Returns:
      the first input element which is a member of this form and has the specified name
      Throws:
      ElementNotFoundException - if there is not input in this form with the specified name
    • getSelectsByName

      public List<HtmlSelect> getSelectsByName(String name)
      Returns all the HtmlSelect elements in this form that have the specified name.
      Parameters:
      name - the name to search for
      Returns:
      all the HtmlSelect elements in this form that have the specified name
    • getSelectByName

      public HtmlSelect getSelectByName(String name) throws ElementNotFoundException
      Returns the first HtmlSelect element in this form that has the specified name.
      Parameters:
      name - the name to search for
      Returns:
      the first HtmlSelect element in this form that has the specified name
      Throws:
      ElementNotFoundException - if this form does not contain a HtmlSelect element with the specified name
    • getButtonsByName

      public List<HtmlButton> getButtonsByName(String name)
      Returns all the HtmlButton elements in this form that have the specified name.
      Parameters:
      name - the name to search for
      Returns:
      all the HtmlButton elements in this form that have the specified name
    • getButtonByName

      public HtmlButton getButtonByName(String name) throws ElementNotFoundException
      Returns the first HtmlButton element in this form that has the specified name.
      Parameters:
      name - the name to search for
      Returns:
      the first HtmlButton element in this form that has the specified name
      Throws:
      ElementNotFoundException - if this form does not contain a HtmlButton element with the specified name
    • getTextAreasByName

      public List<HtmlTextArea> getTextAreasByName(String name)
      Returns all the HtmlTextArea elements in this form that have the specified name.
      Parameters:
      name - the name to search for
      Returns:
      all the HtmlTextArea elements in this form that have the specified name
    • getTextAreaByName

      public HtmlTextArea getTextAreaByName(String name) throws ElementNotFoundException
      Returns the first HtmlTextArea element in this form that has the specified name.
      Parameters:
      name - the name to search for
      Returns:
      the first HtmlTextArea element in this form that has the specified name
      Throws:
      ElementNotFoundException - if this form does not contain a HtmlTextArea element with the specified name
    • getRadioButtonsByName

      public List<HtmlRadioButtonInput> getRadioButtonsByName(String name)
      Returns all the HtmlRadioButtonInput elements in this form that have the specified name.
      Parameters:
      name - the name to search for
      Returns:
      all the HtmlRadioButtonInput elements in this form that have the specified name
    • getCheckedRadioButton

      public HtmlRadioButtonInput getCheckedRadioButton(String name)
      Returns the first checked radio button with the specified name. If none of the radio buttons by that name are checked, this method returns null.
      Parameters:
      name - the name of the radio button
      Returns:
      the first checked radio button with the specified name
    • getActionAttribute

      public final String getActionAttribute()
      Returns the value of the attribute action. Refer to the HTML 4.01 documentation for details on the use of this attribute.
      Returns:
      the value of the attribute action or an empty string if that attribute isn't defined
    • setActionAttribute

      public final void setActionAttribute(String action)
      Sets the value of the attribute action. Refer to the HTML 4.01 documentation for details on the use of this attribute.
      Parameters:
      action - the value of the attribute action
    • getMethodAttribute

      public final String getMethodAttribute()
      Returns the value of the attribute method. Refer to the HTML 4.01 documentation for details on the use of this attribute.
      Returns:
      the value of the attribute method or an empty string if that attribute isn't defined
    • setMethodAttribute

      public final void setMethodAttribute(String method)
      Sets the value of the attribute method. Refer to the HTML 4.01 documentation for details on the use of this attribute.
      Parameters:
      method - the value of the attribute method
    • getNameAttribute

      public final String getNameAttribute()
      Returns the value of the attribute name. Refer to the HTML 4.01 documentation for details on the use of this attribute.
      Returns:
      the value of the attribute name or an empty string if that attribute isn't defined
    • setNameAttribute

      public final void setNameAttribute(String name)
      Sets the value of the attribute name. Refer to the HTML 4.01 documentation for details on the use of this attribute.
      Parameters:
      name - the value of the attribute name
    • getEnctypeAttribute

      public final String getEnctypeAttribute()
      Returns the value of the attribute enctype. Refer to the HTML 4.01 documentation for details on the use of this attribute. "Enctype" is the encoding type used when submitting a form back to the server.
      Returns:
      the value of the attribute enctype or an empty string if that attribute isn't defined
    • setEnctypeAttribute

      public final void setEnctypeAttribute(String encoding)
      Sets the value of the attribute enctype. Refer to the HTML 4.01 documentation for details on the use of this attribute. "Enctype" is the encoding type used when submitting a form back to the server.
      Parameters:
      encoding - the value of the attribute enctype
    • getOnSubmitAttribute

      public final String getOnSubmitAttribute()
      Returns the value of the attribute onsubmit. Refer to the HTML 4.01 documentation for details on the use of this attribute.
      Returns:
      the value of the attribute onsubmit or an empty string if that attribute isn't defined
    • getOnResetAttribute

      public final String getOnResetAttribute()
      Returns the value of the attribute onreset. Refer to the HTML 4.01 documentation for details on the use of this attribute.
      Returns:
      the value of the attribute onreset or an empty string if that attribute isn't defined
    • getAcceptAttribute

      public final String getAcceptAttribute()
      Returns the value of the attribute accept. Refer to the HTML 4.01 documentation for details on the use of this attribute.
      Returns:
      the value of the attribute accept or an empty string if that attribute isn't defined
    • getAcceptCharsetAttribute

      public final String getAcceptCharsetAttribute()
      Returns the value of the attribute accept-charset. Refer to the HTML 4.01 documentation for details on the use of this attribute.
      Returns:
      the value of the attribute accept-charset or an empty string if that attribute isn't defined
    • getTargetAttribute

      public final String getTargetAttribute()
      Returns the value of the attribute target. Refer to the HTML 4.01 documentation for details on the use of this attribute.
      Returns:
      the value of the attribute target or an empty string if that attribute isn't defined
    • setTargetAttribute

      public final void setTargetAttribute(String target)
      Sets the value of the attribute target. Refer to the HTML 4.01 documentation for details on the use of this attribute.
      Parameters:
      target - the value of the attribute target
    • getRelAttribute

      public final String getRelAttribute()
      Returns the value of the attribute rel. Refer to the HTML 4.01 documentation for details on the use of this attribute.
      Returns:
      the value of the attribute rel or an empty string if that attribute isn't defined
    • getInputByValue

      public <I extends HtmlInput> I getInputByValue(String value) throws ElementNotFoundException
      Returns the first input in this form with the specified value.
      Type Parameters:
      I - the input type
      Parameters:
      value - the value to search for
      Returns:
      the first input in this form with the specified value
      Throws:
      ElementNotFoundException - if this form does not contain any inputs with the specified value
    • getInputsByValue

      public List<HtmlInput> getInputsByValue(String value)
      Returns all the inputs in this form with the specified value.
      Parameters:
      value - the value to search for
      Returns:
      all the inputs in this form with the specified value
    • preventDefault

      protected void preventDefault()
      This method is called if the current fired event is canceled by preventDefault().

      The default implementation does nothing.

      Overrides:
      preventDefault in class DomElement
    • isEmptyXmlTagExpanded

      protected boolean isEmptyXmlTagExpanded()
      Browsers have problems with self closing form tags.
      Overrides:
      isEmptyXmlTagExpanded in class DomElement
      Returns:
      false by default
    • isNoValidate

      public final boolean isNoValidate()
      Returns:
      the value of the attribute novalidate or an empty string if that attribute isn't defined
    • setNoValidate

      public final void setNoValidate(boolean noValidate)
      Sets the value of the attribute novalidate.
      Parameters:
      noValidate - the value of the attribute novalidate