Class Button


@Marshalled(typeName="button") public class Button extends HtmlElementMixed<Button>
DTO for an HTML <button> element.

The button element represents a clickable button that can be used to submit forms, trigger actions, or perform other interactive functions. Unlike input elements, buttons can contain rich content including text, images, and other HTML elements.

Examples:

// Simple submit button Button btn1 = button().type("submit").text("Submit Form"); // Button with custom styling and click handler Button btn2 = button() .type("button") .class_("btn btn-primary") .onclick("handleClick()") .text("Click Me"); // Button with form override attributes Button btn3 = button() .type("submit") .formaction("https://api.example.com/submit") .formmethod("post") .formtarget("_blank") .text("Submit to API"); // Button with icon and text Button btn4 = button() .type("button") .children( span().class_("icon").text("📧"), span().text("Send Email") );

The following convenience methods are provided for constructing instances of this bean:

See Also:
  • Constructor Details

  • Method Details

    • autofocus

      public Button autofocus(Object value)
      autofocus attribute.

      Automatically focus the form control when the page is loaded.

      Parameters:
      value - The new value for this attribute. Typically a Boolean or String. Can be null to unset the attribute.
      Returns:
      This object.
    • disabled

      public Button disabled(Object value)
      disabled attribute.

      Whether the form control is disabled.

      This attribute uses deminimized values:

      • false - Attribute is not added
      • true - Attribute is added as "disabled"
      • Other values - Passed through as-is
      Parameters:
      value - The new value for this attribute. Typically a Boolean or String. Can be null to unset the attribute.
      Returns:
      This object.
    • form

      public Button form(String value)
      form attribute.

      Associates the button with a form element by specifying the form's ID. This allows the button to be placed outside the form element while still being part of the form submission.

      The value should match the ID of a form element in the same document.

      Parameters:
      value - The ID of the form element to associate with this button. Can be null to unset the attribute.
      Returns:
      This object.
    • formaction

      public Button formaction(String value)
      formaction attribute.

      Specifies the URL where the form data will be submitted when this button is clicked. Overrides the form's action attribute.

      The value can be of any of the following types: URI, URL, String. Strings must be valid URIs.

      URIs defined by UriResolver can be used for values.

      Parameters:
      value - The URL where the form data will be submitted. Can be null, in which case the attribute is stored with a null value (not removed).
      Returns:
      This object.
    • formenctype

      public Button formenctype(String value)
      formenctype attribute.

      Specifies how form data should be encoded when submitted. Overrides the form's enctype attribute.

      Possible values:

      • "application/x-www-form-urlencoded" - Default encoding (default)
      • "multipart/form-data" - For file uploads
      • "text/plain" - Plain text encoding
      Parameters:
      value - The encoding type for form submission. Can be null to unset the attribute.
      Returns:
      This object.
    • formmethod

      public Button formmethod(String value)
      formmethod attribute.

      Specifies the HTTP method to use for form submission. Overrides the form's method attribute.

      Possible values:

      • "get" - Form data is sent as URL parameters
      • "post" - Form data is sent in the request body (default)
      • "dialog" - Used for forms within dialog elements
      Parameters:
      value - The HTTP method for form submission. Can be null to unset the attribute.
      Returns:
      This object.
    • formnovalidate

      public Button formnovalidate(String value)
      formnovalidate attribute.

      Specifies that form validation should be bypassed when this button submits the form. Overrides the form's novalidate attribute.

      This attribute uses deminimized values:

      • false - Form validation is performed (default)
      • true - Form validation is bypassed
      • Other values - Passed through as-is
      Parameters:
      value - Whether to bypass form validation. Can be null to unset the attribute.
      Returns:
      This object.
    • formtarget

      public Button formtarget(String value)
      formtarget attribute.

      Specifies where to display the form response after submission. Overrides the form's target attribute.

      Common values:

      • "_blank" - Open in a new window/tab
      • "_self" - Open in the same frame (default)
      • "_parent" - Open in the parent frame
      • "_top" - Open in the full body of the window
      • "framename" - Open in a named frame
      Parameters:
      value - Where to display the form response. Can be null to unset the attribute.
      Returns:
      This object.
    • name

      public Button name(String value)
      name attribute.

      Specifies the name of the button. This name is used when the form is submitted and can be used to access the element via the form.elements API.

      The name should be unique within the form and should not contain spaces or special characters.

      Parameters:
      value - The name of the button for submission and API access. Can be null to unset the attribute.
      Returns:
      This object.
    • type

      public Button type(String value)
      type attribute.

      Specifies the type of button and its behavior when clicked.

      Possible values:

      • "submit" - Submits the form (default)
      • "reset" - Resets the form to its initial state
      • "button" - Generic button with no default behavior
      Parameters:
      value - The type of button and its behavior. Can be null to unset the attribute.
      Returns:
      This object.
    • value

      public Button value(Object value)
      value attribute.

      Value to be used for form submission.

      Parameters:
      value - The new value for this attribute. Typically a Number or String. Can be null to unset the attribute.
      Returns:
      This object.