Class Button


@Bean(typeName="button") public class Button extends HtmlElementMixed
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:
      autofocus - The new value for this attribute. Typically a Boolean or String.
      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:
      disabled - The new value for this attribute. Typically a Boolean or String.
      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:
      form - The ID of the form element to associate with this button.
      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:
      formaction - The URL where the form data will be submitted.
      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:
      formenctype - The encoding type for form submission.
      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:
      formmethod - The HTTP method for form submission.
      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:
      formnovalidate - Whether to bypass form validation.
      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:
      formtarget - Where to display the form response.
      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:
      name - The name of the button for submission and API access.
      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:
      type - The type of button and its behavior.
      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.
      Returns:
      This object.
    • _class

      public Button _class(String value)
      Description copied from class: HtmlElement
      class attribute.

      Specifies one or more CSS class names for the element, separated by spaces. These classes can be used for styling and JavaScript selection.

      Overrides:
      _class in class HtmlElementMixed
      Returns:
      This object.
    • accesskey

      public Button accesskey(String value)
      Description copied from class: HtmlElement
      accesskey attribute.

      Defines a keyboard shortcut to activate or focus an element. The value should be a single character that, when pressed with a modifier key (usually Alt), activates the element.

      Overrides:
      accesskey in class HtmlElementMixed
      Returns:
      This object.
    • contenteditable

      public Button contenteditable(Object value)
      Description copied from class: HtmlElement
      contenteditable attribute.

      Indicates whether the element's content is editable by the user.

      Possible values:

      • "true" or empty string - Element content is editable
      • "false" - Element content is not editable
      • "plaintext-only" - Element content is editable, but rich text formatting is disabled
      Overrides:
      contenteditable in class HtmlElementMixed
      Returns:
      This object.
    • dir

      public Button dir(String value)
      Description copied from class: HtmlElement
      dir attribute.

      Specifies the text direction of the element's content.

      Possible values:

      • "ltr" - Left-to-right text direction
      • "rtl" - Right-to-left text direction
      • "auto" - Browser determines direction based on content
      Overrides:
      dir in class HtmlElementMixed
      Returns:
      This object.
    • hidden

      public Button hidden(Object value)
      Description copied from class: HtmlElement
      hidden attribute.

      This attribute uses deminimized values:

      • false - Attribute is not added
      • true - Attribute is added as "hidden"
      • Other values - Passed through as-is
      Overrides:
      hidden in class HtmlElementMixed
      Returns:
      This object.
    • id

      public Button id(String value)
      Description copied from class: HtmlElement
      id attribute.

      Specifies a unique identifier for the element. The ID must be unique within the document and can be used for CSS styling, JavaScript selection, and anchor links.

      Overrides:
      id in class HtmlElementMixed
      Returns:
      This object.
    • lang

      public Button lang(String value)
      Description copied from class: HtmlElement
      lang attribute.

      Specifies the primary language of the element's content using a language tag. This helps with accessibility, search engines, and browser features like spell checking.

      Overrides:
      lang in class HtmlElementMixed
      Returns:
      This object.
    • onabort

      public Button onabort(String value)
      Description copied from class: HtmlElement
      onabort attribute.

      Event handler for when an operation is aborted (e.g., image loading is cancelled).

      Overrides:
      onabort in class HtmlElementMixed
      Returns:
      This object.
    • onblur

      public Button onblur(String value)
      Description copied from class: HtmlElement
      onblur attribute.

      Event handler for when the element loses focus.

      Note:

      If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities. For example:

      • If using single quotes for attributes: onblur("validate(\"email\")")
      • If using double quotes for attributes: onblur("validate('email')")
      Overrides:
      onblur in class HtmlElementMixed
      Returns:
      This object.
    • oncancel

      public Button oncancel(String value)
      Description copied from class: HtmlElement
      oncancel attribute.

      Event handler for when a dialog is cancelled.

      Overrides:
      oncancel in class HtmlElementMixed
      Returns:
      This object.
    • oncanplay

      public Button oncanplay(String value)
      Description copied from class: HtmlElement
      oncanplay attribute.

      Event handler for when the media can start playing (enough data has been buffered).

      Overrides:
      oncanplay in class HtmlElementMixed
      Returns:
      This object.
    • oncanplaythrough

      public Button oncanplaythrough(String value)
      Description copied from class: HtmlElement
      oncanplaythrough attribute.

      Event handler for when the media can play through to the end without buffering.

      Overrides:
      oncanplaythrough in class HtmlElementMixed
      Returns:
      This object.
    • onchange

      public Button onchange(String value)
      Description copied from class: HtmlElement
      onchange attribute.

      Event handler for when the value of a form element changes and loses focus.

      Note:

      If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities. For example:

      • If using single quotes for attributes: onchange("validate(\"field\")")
      • If using double quotes for attributes: onchange("validate('field')")
      Overrides:
      onchange in class HtmlElementMixed
      Returns:
      This object.
    • onclick

      public Button onclick(String value)
      Description copied from class: HtmlElement
      onclick attribute.

      Event handler for when the element is clicked.

      Note:

      If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities. For example:

      • If using single quotes for attributes: onclick("alert(\"Hello\")")
      • If using double quotes for attributes: onclick("alert('Hello')")
      Overrides:
      onclick in class HtmlElementMixed
      Returns:
      This object.
    • oncuechange

      public Button oncuechange(String value)
      Description copied from class: HtmlElement
      oncuechange attribute.

      Event handler for when a text track cue changes.

      Overrides:
      oncuechange in class HtmlElementMixed
      Returns:
      This object.
    • ondblclick

      public Button ondblclick(String value)
      Description copied from class: HtmlElement
      ondblclick attribute.

      Event handler for when the element is double-clicked.

      Overrides:
      ondblclick in class HtmlElementMixed
      Returns:
      This object.
    • ondurationchange

      public Button ondurationchange(String value)
      Description copied from class: HtmlElement
      ondurationchange attribute.

      Event handler for when the duration of the media changes.

      Overrides:
      ondurationchange in class HtmlElementMixed
      Returns:
      This object.
    • onemptied

      public Button onemptied(String value)
      Description copied from class: HtmlElement
      onemptied attribute.

      Event handler for when the media element becomes empty (e.g., network error).

      Overrides:
      onemptied in class HtmlElementMixed
      Returns:
      This object.
    • onended

      public Button onended(String value)
      Description copied from class: HtmlElement
      onended attribute.

      Event handler for when the media playback reaches the end.

      Overrides:
      onended in class HtmlElementMixed
      Returns:
      This object.
    • onerror

      public Button onerror(String value)
      Description copied from class: HtmlElement
      onerror attribute.

      Event handler for when an error occurs (e.g., failed resource loading).

      Overrides:
      onerror in class HtmlElementMixed
      Returns:
      This object.
    • onfocus

      public Button onfocus(String value)
      Description copied from class: HtmlElement
      onfocus attribute.

      Event handler for when the element receives focus.

      Note:

      If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities. For example:

      • If using single quotes for attributes: onfocus("highlight(\"field\")")
      • If using double quotes for attributes: onfocus("highlight('field')")
      Overrides:
      onfocus in class HtmlElementMixed
      Returns:
      This object.
    • oninput

      public Button oninput(String value)
      Description copied from class: HtmlElement
      oninput attribute.

      Event handler for when the value of an input element changes (fires on every keystroke).

      Overrides:
      oninput in class HtmlElementMixed
      Returns:
      This object.
    • oninvalid

      public Button oninvalid(String value)
      Description copied from class: HtmlElement
      oninvalid attribute.

      Event handler for when form validation fails.

      Overrides:
      oninvalid in class HtmlElementMixed
      Returns:
      This object.
    • onkeydown

      public Button onkeydown(String value)
      Description copied from class: HtmlElement
      onkeydown attribute.

      Event handler for when a key is pressed down.

      Overrides:
      onkeydown in class HtmlElementMixed
      Returns:
      This object.
    • onkeypress

      public Button onkeypress(String value)
      Description copied from class: HtmlElement
      onkeypress attribute.

      Event handler for when a key is pressed (deprecated, use onkeydown instead).

      Overrides:
      onkeypress in class HtmlElementMixed
      Returns:
      This object.
    • onkeyup

      public Button onkeyup(String value)
      Description copied from class: HtmlElement
      onkeyup attribute.

      Event handler for when a key is released.

      Overrides:
      onkeyup in class HtmlElementMixed
      Returns:
      This object.
    • onload

      public Button onload(String value)
      Description copied from class: HtmlElement
      onload attribute.

      Event handler for when the element and its resources have finished loading.

      Note:

      If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities. For example:

      • If using single quotes for attributes: onload("init(\"config\")")
      • If using double quotes for attributes: onload("init('config')")
      Overrides:
      onload in class HtmlElementMixed
      Returns:
      This object.
    • onloadeddata

      public Button onloadeddata(String value)
      Description copied from class: HtmlElement
      onloadeddata attribute.

      Event handler for when the first frame of media has finished loading.

      Overrides:
      onloadeddata in class HtmlElementMixed
      Returns:
      This object.
    • onloadedmetadata

      public Button onloadedmetadata(String value)
      Description copied from class: HtmlElement
      onloadedmetadata attribute.

      Event handler for when metadata (duration, dimensions, etc.) has been loaded.

      Overrides:
      onloadedmetadata in class HtmlElementMixed
      Returns:
      This object.
    • onloadstart

      public Button onloadstart(String value)
      Description copied from class: HtmlElement
      onloadstart attribute.

      Event handler for when the browser starts loading the media.

      Overrides:
      onloadstart in class HtmlElementMixed
      Returns:
      This object.
    • onmousedown

      public Button onmousedown(String value)
      Description copied from class: HtmlElement
      onmousedown attribute.

      Event handler for when a mouse button is pressed down on the element.

      Overrides:
      onmousedown in class HtmlElementMixed
      Returns:
      This object.
    • onmouseenter

      public Button onmouseenter(String value)
      Description copied from class: HtmlElement
      onmouseenter attribute.

      Event handler for when the mouse pointer enters the element (does not bubble).

      Overrides:
      onmouseenter in class HtmlElementMixed
      Returns:
      This object.
    • onmouseleave

      public Button onmouseleave(String value)
      Description copied from class: HtmlElement
      onmouseleave attribute.

      Event handler for when the mouse pointer leaves the element (does not bubble).

      Overrides:
      onmouseleave in class HtmlElementMixed
      Returns:
      This object.
    • onmousemove

      public Button onmousemove(String value)
      Description copied from class: HtmlElement
      onmousemove attribute.

      Event handler for when the mouse pointer moves over the element.

      Overrides:
      onmousemove in class HtmlElementMixed
      Returns:
      This object.
    • onmouseout

      public Button onmouseout(String value)
      Description copied from class: HtmlElement
      onmouseout attribute.

      Event handler for when the mouse pointer moves out of the element (bubbles).

      Overrides:
      onmouseout in class HtmlElementMixed
      Returns:
      This object.
    • onmouseover

      public Button onmouseover(String value)
      Description copied from class: HtmlElement
      onmouseover attribute.

      Event handler for when the mouse pointer moves over the element (bubbles).

      Note:

      If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities. For example:

      • If using single quotes for attributes: onmouseover("showTooltip(\"info\")")
      • If using double quotes for attributes: onmouseover("showTooltip('info')")
      Overrides:
      onmouseover in class HtmlElementMixed
      Returns:
      This object.
    • onmouseup

      public Button onmouseup(String value)
      Description copied from class: HtmlElement
      onmouseup attribute.

      Event handler for when a mouse button is released over the element.

      Overrides:
      onmouseup in class HtmlElementMixed
      Returns:
      This object.
    • onmousewheel

      public Button onmousewheel(String value)
      Description copied from class: HtmlElement
      onmousewheel attribute.

      Event handler for when the mouse wheel is rotated over the element (deprecated, use onwheel).

      Overrides:
      onmousewheel in class HtmlElementMixed
      Returns:
      This object.
    • onpause

      public Button onpause(String value)
      Description copied from class: HtmlElement
      onpause attribute.

      Event handler for when media playback is paused.

      Overrides:
      onpause in class HtmlElementMixed
      Returns:
      This object.
    • onplay

      public Button onplay(String value)
      Description copied from class: HtmlElement
      onplay attribute.

      Event handler for when media playback starts.

      Overrides:
      onplay in class HtmlElementMixed
      Returns:
      This object.
    • onplaying

      public Button onplaying(String value)
      Description copied from class: HtmlElement
      onplaying attribute.

      Event handler for when media playback starts after being paused or delayed.

      Overrides:
      onplaying in class HtmlElementMixed
      Returns:
      This object.
    • onprogress

      public Button onprogress(String value)
      Description copied from class: HtmlElement
      onprogress attribute.

      Event handler for when the browser is downloading media data.

      Overrides:
      onprogress in class HtmlElementMixed
      Returns:
      This object.
    • onratechange

      public Button onratechange(String value)
      Description copied from class: HtmlElement
      onratechange attribute.

      Event handler for when the playback rate of media changes.

      Overrides:
      onratechange in class HtmlElementMixed
      Returns:
      This object.
    • onreset

      public Button onreset(String value)
      Description copied from class: HtmlElement
      onreset attribute.

      Event handler for when a form is reset.

      Overrides:
      onreset in class HtmlElementMixed
      Returns:
      This object.
    • onresize

      public Button onresize(String value)
      Description copied from class: HtmlElement
      onresize attribute.

      Event handler for when the element is resized.

      Overrides:
      onresize in class HtmlElementMixed
      Returns:
      This object.
    • onscroll

      public Button onscroll(String value)
      Description copied from class: HtmlElement
      onscroll attribute.

      Event handler for when the element's scrollbar is scrolled.

      Overrides:
      onscroll in class HtmlElementMixed
      Returns:
      This object.
    • onseeked

      public Button onseeked(String value)
      Description copied from class: HtmlElement
      onseeked attribute.

      Event handler for when a seek operation completes.

      Overrides:
      onseeked in class HtmlElementMixed
      Returns:
      This object.
    • onseeking

      public Button onseeking(String value)
      Description copied from class: HtmlElement
      onseeking attribute.

      Event handler for when a seek operation begins.

      Overrides:
      onseeking in class HtmlElementMixed
      Returns:
      This object.
    • onselect

      public Button onselect(String value)
      Description copied from class: HtmlElement
      onselect attribute.

      Event handler for when text is selected in the element.

      Overrides:
      onselect in class HtmlElementMixed
      Returns:
      This object.
    • onshow

      public Button onshow(String value)
      Description copied from class: HtmlElement
      onshow attribute.

      Event handler for when a context menu is shown.

      Overrides:
      onshow in class HtmlElementMixed
      Returns:
      This object.
    • onstalled

      public Button onstalled(String value)
      Description copied from class: HtmlElement
      onstalled attribute.

      Event handler for when media loading is stalled.

      Overrides:
      onstalled in class HtmlElementMixed
      Returns:
      This object.
    • onsubmit

      public Button onsubmit(String value)
      Description copied from class: HtmlElement
      onsubmit attribute.

      Event handler for when a form is submitted.

      Note:

      If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities. For example:

      • If using single quotes for attributes: onsubmit("return validate(\"form\")")
      • If using double quotes for attributes: onsubmit("return validate('form')")
      Overrides:
      onsubmit in class HtmlElementMixed
      Returns:
      This object.
    • onsuspend

      public Button onsuspend(String value)
      Description copied from class: HtmlElement
      onsuspend attribute.

      Event handler for when media loading is suspended.

      Overrides:
      onsuspend in class HtmlElementMixed
      Returns:
      This object.
    • ontimeupdate

      public Button ontimeupdate(String value)
      Description copied from class: HtmlElement
      ontimeupdate attribute.

      Event handler for when the current playback position changes.

      Overrides:
      ontimeupdate in class HtmlElementMixed
      Returns:
      This object.
    • ontoggle

      public Button ontoggle(String value)
      Description copied from class: HtmlElement
      ontoggle attribute.

      Event handler for when a details element is opened or closed.

      Overrides:
      ontoggle in class HtmlElementMixed
      Returns:
      This object.
    • onvolumechange

      public Button onvolumechange(String value)
      Description copied from class: HtmlElement
      onvolumechange attribute.

      Event handler for when the volume of media changes.

      Overrides:
      onvolumechange in class HtmlElementMixed
      Returns:
      This object.
    • onwaiting

      public Button onwaiting(String value)
      Description copied from class: HtmlElement
      onwaiting attribute.

      Event handler for when media playback stops to buffer more data.

      Overrides:
      onwaiting in class HtmlElementMixed
      Returns:
      This object.
    • spellcheck

      public Button spellcheck(Object value)
      Description copied from class: HtmlElement
      spellcheck attribute.

      Indicates whether the element should have its spelling and grammar checked.

      Possible values:

      • "true" - Enable spell checking for this element
      • "false" - Disable spell checking for this element
      Overrides:
      spellcheck in class HtmlElementMixed
      Returns:
      This object.
    • style

      public Button style(String value)
      Description copied from class: HtmlElement
      style attribute.

      Specifies inline CSS styles for the element. The value should be valid CSS property-value pairs separated by semicolons.

      Overrides:
      style in class HtmlElementMixed
      Returns:
      This object.
    • tabindex

      public Button tabindex(Object value)
      Description copied from class: HtmlElement
      tabindex attribute.

      Specifies the tab order of the element when navigating with the keyboard.

      Possible values:

      • Positive integer - Element is focusable and participates in tab order
      • "0" - Element is focusable but not in tab order
      • Negative integer - Element is not focusable
      Overrides:
      tabindex in class HtmlElementMixed
      Returns:
      This object.
    • title

      public Button title(String value)
      Description copied from class: HtmlElement
      title attribute.

      Specifies additional information about the element, typically displayed as a tooltip when the user hovers over the element.

      Overrides:
      title in class HtmlElementMixed
      Returns:
      This object.
    • translate

      public Button translate(Object value)
      Description copied from class: HtmlElement
      translate attribute.

      Specifies whether the element's content should be translated when the page is localized.

      Possible values:

      • "yes" - Content should be translated (default)
      • "no" - Content should not be translated
      Overrides:
      translate in class HtmlElementMixed
      Returns:
      This object.
    • child

      public Button child(Object value)
      Description copied from class: HtmlElementMixed
      Adds a child element to this element.
      Overrides:
      child in class HtmlElementMixed
      Returns:
      This object.
    • children

      public Button children(Object... value)
      Description copied from class: HtmlElementMixed
      Adds one or more child elements to this element.
      Overrides:
      children in class HtmlElementMixed
      Returns:
      This object.