Class Button<T extends Button<T>>
<button> element for creating clickable buttons.
The Button class provides a Java representation of the HTML button element, which creates a clickable button that can be used for form submission, triggering actions, or resetting forms. Unlike input buttons, button elements can contain rich content like images and formatted text.
Features:
- Support for button types (submit, reset, button)
- Form association and override capabilities
- Custom form action, method, and encoding for submit buttons
- Form validation control override
- Target window specification override
- Auto-focus capability for keyboard navigation
- Named button values for form submission
- Rich content support (text, images, icons)
Usage Example:
// Create a submit button
Button submitBtn = new Button("Submit Form");
submitBtn.setType(ButtonType.SUBMIT);
submitBtn.setName("submitButton");
submitBtn.setValue("submitted");
// Create a button with custom form action
Button saveBtn = new Button("Save Draft");
saveBtn.setType(ButtonType.SUBMIT);
saveBtn.setFormAction("/save-draft");
saveBtn.setFormMethod(FormMethod.POST);
// Create a reset button
Button resetBtn = new Button("Clear Form");
resetBtn.setType(ButtonType.RESET);
// Create a generic button for JavaScript actions
Button actionBtn = new Button("Click Me");
actionBtn.setType(ButtonType.BUTTON);
actionBtn.setAutoFocus(true);
- Since:
- 2007
- Version:
- 1.0
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringgetForm()Returns the form attribute value.protected StringReturns the formaction attribute value.protected StringReturns the formenctype attribute value.protected StringReturns the formmethod attribute value.protected StringReturns the formtarget attribute value.protected StringgetName()Returns the name attribute value.protected booleanReturns whether the formnovalidate attribute is set.final TsetDisabled(boolean disabled) Sets the disabled boolean attribute.final TAssociates this element with a form element.final TsetFormAction(String url) Overrides the form's action URL when this button is used to submit.final TsetFormEncType(FormEncoding encoding) Sets the form encoding type override using theFormEncodingenum.final TsetFormEncType(String encoding) Sets the formenctype attribute.final TsetFormMethod(FormMethod formMethod) Sets the form method override using theFormMethodenum.final TsetFormMethod(String formMethod) Sets the formmethod attribute.final TsetFormNoValidate(boolean flag) Sets the formnovalidate boolean attribute.final TsetFormTarget(Target target) Sets the form target override using theTargetenum.final TsetFormTarget(String target) Sets the formtarget attribute.final TSets the name attribute.final TsetPopoverTarget(String popoverTarget) Sets the ID of the popover element that this button controls.final TsetPopoverTargetAction(String popoverTargetAction) Sets the action to perform on the target popover element.final TsetType(ButtonType type) Sets the type of this button.final TSets the type of this button.final TSets the value submitted with the form data when this button is used as the submitter.Methods inherited from class com.oorian.html.StyledContainerElement
addElement, addLineOfText, addLineOfText, addLineOfText, addParagraph, addParagraph, addSpacer, addText, addText, addText, addText, insertElement, removeAllElements, removeElement, removeElement, setElement, setText, setText, setText, setTextMethods inherited from class com.oorian.html.StyledElement
addClass, addStyle, addStyle, addStyleAttribute, addTransition, animate, clearTransitions, getActiveStyle, getCssClass, getDisabledStyle, getFocusStyle, getFocusVisibleStyle, getHoverStyle, getHtml, getStyle, getStyleAttribute, hidden, hide, initialize, isDisplayed, isTransitionForwardActive, onHide, onRemovedFromPage, onShow, removeClass, setActiveStyle, setAlignContent, setAlignContent, setAlignItems, setAlignItems, setAlignSelf, setAlignSelf, setAnimation, setAnimationDelay, setAnimationDelay, setAnimationDelay, setAnimationDirection, setAnimationDirection, setAnimationDuration, setAnimationDuration, setAnimationDuration, setAnimationFillMode, setAnimationFillMode, setAnimationIterationCount, setAnimationIterationCount, setAnimationIterationCount, setAnimationName, setAnimationPlayState, setAnimationPlayState, setAnimationTimingFunction, setAnimationTimingFunction, setAnimationTimingFunction, setAnimationTimingFunction, setBackdropFilter, setBackdropFilter, setBackfaceVisibility, setBackfaceVisibility, setBackground, setBackground, setBackgroundAttachment, setBackgroundAttachment, setBackgroundBlendMode, setBackgroundBlendMode, setBackgroundClip, setBackgroundClip, setBackgroundColor, setBackgroundColor, setBackgroundColor, setBackgroundImage, setBackgroundImage, setBackgroundOrigin, setBackgroundOrigin, setBackgroundPosition, setBackgroundPosition, setBackgroundPosition, setBackgroundPosition, setBackgroundPosition, setBackgroundRepeat, setBackgroundRepeat, setBackgroundSize, setBackgroundSize, setBackgroundSize, setBackgroundSize, setBackgroundSize, setBlur, setBorder, setBorder, setBorder, setBorder, setBorder, setBorder, setBorder, setBorder, setBorder, setBorderBottom, setBorderBottom, setBorderBottom, setBorderBottom, setBorderBottom, setBorderBottom, setBorderBottom, setBorderBottom, setBorderBottomColor, setBorderBottomColor, setBorderBottomLeftRadius, setBorderBottomLeftRadius, setBorderBottomLeftRadius, setBorderBottomRightRadius, setBorderBottomRightRadius, setBorderBottomRightRadius, setBorderBottomStyle, setBorderBottomStyle, setBorderBottomWidth, setBorderBottomWidth, setBorderBottomWidth, setBorderBottomWidth, setBorderColor, setBorderColor, setBorderColor, setBorderColor, setBorderImage, setBorderImage, setBorderImageOutset, setBorderImageRepeat, setBorderImageSlice, setBorderImageSource, setBorderImageWidth, setBorderLeft, setBorderLeft, setBorderLeft, setBorderLeft, setBorderLeft, setBorderLeft, setBorderLeft, setBorderLeft, setBorderLeftColor, setBorderLeftColor, setBorderLeftStyle, setBorderLeftStyle, setBorderLeftWidth, setBorderLeftWidth, setBorderLeftWidth, setBorderLeftWidth, setBorderRadius, setBorderRadius, setBorderRadius, setBorderRadius, setBorderRadius, setBorderRadius, setBorderRight, setBorderRight, setBorderRight, setBorderRight, setBorderRight, setBorderRight, setBorderRight, setBorderRight, setBorderRightColor, setBorderRightColor, setBorderRightStyle, setBorderRightStyle, setBorderRightWidth, setBorderRightWidth, setBorderRightWidth, setBorderRightWidth, setBorderStyle, setBorderStyle, setBorderTop, setBorderTop, setBorderTop, setBorderTop, setBorderTop, setBorderTop, setBorderTop, setBorderTop, setBorderTopColor, setBorderTopColor, setBorderTopLeftRadius, setBorderTopLeftRadius, setBorderTopLeftRadius, setBorderTopRightRadius, setBorderTopRightRadius, setBorderTopRightRadius, setBorderTopStyle, setBorderTopStyle, setBorderTopWidth, setBorderTopWidth, setBorderTopWidth, setBorderTopWidth, setBorderWidth, setBorderWidth, setBorderWidth, setBorderWidth, setBorderWidth, setBorderWidth, setBorderWidth, setBottom, setBottom, setBottom, setBoxShadow, setBoxShadow, setBoxShadow, setBoxShadow, setBoxShadow, setBoxSizing, setBoxSizing, setBreakAfter, setBreakBefore, setBreakInside, setBrightness, setClass, setClear, setClear, setClip, setClipPath, setClipPath, setColGap, setColGap, setColor, setColor, setColumnCount, setColumnCount, setColumnFill, setColumnFill, setColumnGap, setColumnRule, setColumnRuleColor, setColumnRuleColor, setColumnRuleStyle, setColumnRuleStyle, setColumnRuleWidth, setColumnRuleWidth, setColumns, setColumns, setColumns, setColumnSpan, setColumnWidth, setColumnWidth, setColumnWidth, setContrast, setCounterIncrement, setCounterReset, setCursor, setCursor, setDirection, setDirection, setDisabledStyle, setDisplay, setDisplay, setFilter, setFilter, setFilterOpacity, setFlex, setFlexBasis, setFlexDirection, setFlexDirection, setFlexFlow, setFlexGrow, setFlexGrow, setFlexShrink, setFlexShrink, setFlexWrap, setFlexWrap, setFloat, setFloat, setFocusStyle, setFocusVisibleStyle, setFont, setFont, setFont, setFont, setFont, setFont, setFont, setFont, setFont, setFont, setFont, setFont, setFontFace, setFontFamily, setFontFamily, setFontFeatureSettings, setFontKerning, setFontLanguageOverride, setFontSize, setFontSize, setFontSize, setFontSizeAdjust, setFontStretch, setFontStretch, setFontStyle, setFontStyle, setFontSynthesis, setFontVariant, setFontVariant, setFontVariantAlternates, setFontVariantCaps, setFontVariantEastAsian, setFontVariantLigatures, setFontVariantNumeric, setFontVariantPosition, setFontWeight, setFontWeight, setGap, setGap, setGap, setGap, setGrayscale, setHangingPunctuation, setHangingPunctuation, setHeight, setHeight, setHeight, setHoverStyle, setHueRotate, setHyphens, setImageOrientation, setImageRendering, setImageResolution, setImeMode, setInvert, setJustifyContent, setJustifyContent, setKeyFrames, setLeft, setLeft, setLeft, setLetterSpacing, setLetterSpacing, setLetterSpacing, setLetterSpacing, setLineBreak, setLineHeight, setLineHeight, setLineHeight, setLineHeight, setMargin, setMargin, setMargin, setMargin, setMargin, setMarginBottom, setMarginBottom, setMarginBottom, setMarginLeft, setMarginLeft, setMarginLeft, setMarginRight, setMarginRight, setMarginRight, setMarginTop, setMarginTop, setMarginTop, setMark, setMarkAfter, setMarkBefore, setMarks, setMarqueeDirection, setMarqueePlayCount, setMarqueeSpeed, setMarqueeStyle, setMask, setMaskType, setMaxHeight, setMaxHeight, setMaxHeight, setMaxHeightToWindowHeight, setMaxWidth, setMaxWidth, setMaxWidth, setMaxWidthToWindowWidth, setMinHeight, setMinHeight, setMinHeight, setMinHeightToWindowHeight, setMinWidth, setMinWidth, setMinWidth, setMinWidthToWindowWidth, setNavDown, setNavIndex, setNavIndex, setNavLeft, setNavRight, setNavUp, setObjectFit, setObjectPosition, setOnClickNavigateBack, setOnClickNavigateBack, setOnClickNavigateBack, setOnClickNavigateForward, setOnClickNavigateForward, setOnClickNavigateForward, setOnClickNavigateTo, setOnDblClick, setOnDblClickChange, setOpacity, setOpacity, setOrder, setOrder, setOrphans, setOutline, setOutline, setOutline, setOutline, setOutlineColor, setOutlineColor, setOutlineOffset, setOutlineOffset, setOutlineOffset, setOutlineStyle, setOutlineStyle, setOutlineWidth, setOutlineWidth, setOutlineWidth, setOutlineWidth, setOverflow, setOverflow, setOverflow, setOverflowWrap, setOverflowX, setOverflowX, setOverflowY, setOverflowY, setPadding, setPadding, setPadding, setPadding, setPadding, setPadding, setPadding, setPadding, setPaddingBottom, setPaddingBottom, setPaddingBottom, setPaddingLeft, setPaddingLeft, setPaddingLeft, setPaddingRight, setPaddingRight, setPaddingRight, setPaddingTop, setPaddingTop, setPaddingTop, setPageBreakAfter, setPageBreakAfter, setPageBreakBefore, setPageBreakBefore, setPageBreakInside, setPageBreakInside, setPerspective, setPerspective, setPerspective, setPerspectiveOrigin, setPerspectiveOrigin, setPerspectiveOrigin, setPerspectiveOrigin, setPhonemes, setPosition, setPosition, setPosition, setPosition, setPosition, setQuotes, setResize, setResize, setResizeToWindowHeight, setResizeToWindowHeight, setResizeToWindowWidth, setRest, setRestAfter, setRestBefore, setRight, setRight, setRight, setRotate, setRotate, setRowGap, setRowGap, setSaturate, setScale, setScale, setSepia, setShow, setSize, setSize, setSize, setSkewX, setSkewY, setStyle, setStyle, setTabSize, setTabSize, setTabSize, setTabSize, setTextAlign, setTextAlign, setTextAlignLast, setTextAlignLast, setTextCombineUpright, setTextCombineWeight, setTextDecoration, setTextDecoration, setTextDecorationColor, setTextDecorationColor, setTextDecorationLine, setTextDecorationLine, setTextDecorationStyle, setTextDecorationStyle, setTextIndent, setTextIndent, setTextIndent, setTextIndent, setTextJustify, setTextJustify, setTextOrientation, setTextOverflow, setTextOverflow, setTextSelectDisabled, setTextShadow, setTextShadow, setTextShadow, setTextShadow, setTextShadow, setTextTransform, setTextTransform, setTextUnderlinePosition, setTop, setTop, setTop, setTransform, setTransform, setTransformOrigin, setTransformOrigin, setTransformOrigin, setTransformOrigin, setTransformOrigin, setTransformStyle, setTransformStyle, setTransition, setTransitionDelay, setTransitionDelay, setTransitionDelay, setTransitionDuration, setTransitionDuration, setTransitionDuration, setTransitionProperty, setTransitionTimingFunction, setTransitionTimingFunction, setTransitionTimingFunction, setTransitionTimingFunction, setTranslateX, setTranslateY, setTranslateZ, setUnicodeBidi, setUnicodeBidi, setVerticalAlign, setVerticalAlign, setVisibility, setVisibility, setVoiceBalance, setVoiceDuration, setVoicePitch, setVoicePitchRange, setVoiceRate, setVoiceStress, setVoiceVolume, setWhiteSpace, setWhiteSpace, setWidows, setWidth, setWidth, setWidth, setWordBreak, setWordBreak, setWordSpacing, setWordSpacing, setWordSpacing, setWordSpacing, setWordWrap, setWordWrap, setWritingMode, setZIndex, setZIndex, show, shown, stopAnimation, transitionForward, transitionForward, transitionReverse, transitionReverse, updateStyle, updateStyle, updateStyleIfChangedMethods inherited from class com.oorian.html.VisualElement
clearOnClick, click, disable, enable, getAccessKey, getAutoCapitalize, getEnterKeyHint, getInputMode, getPopover, getRole, getTabIndex, getTitle, isAutoFocus, isContentEditable, isDisabled, isDraggable, isHidden, isInert, isSpellCheck, onDisabled, onEnabled, setAccessKey, setAriaAtomic, setAriaBusy, setAriaChecked, setAriaCheckedMixed, setAriaControls, setAriaCurrent, setAriaDescribedBy, setAriaDisabled, setAriaErrorMessage, setAriaExpanded, setAriaHasPopup, setAriaHasPopup, setAriaHidden, setAriaInvalid, setAriaLabel, setAriaLabelledBy, setAriaLevel, setAriaLive, setAriaModal, setAriaOwns, setAriaPressed, setAriaRequired, setAriaSelected, setAriaValueRange, setAriaValueText, setAutoCapitalize, setAutoFocus, setConsumeEvent, setContentEditable, setDraggable, setDropAllowed, setEnterKeyHint, setFocus, setHidden, setInert, setInputMode, setOnAnimationCancel, setOnAnimationEnd, setOnAnimationIteration, setOnAnimationStart, setOnAuxClick, setOnBeforeInput, setOnBeforeToggle, setOnBlur, setOnChange, setOnClick, setOnClickChange, setOnCompositionEnd, setOnCompositionStart, setOnCompositionUpdate, setOnContextMenu, setOnCopy, setOnCut, setOnDocumentResize, setOnFocus, setOnFocusIn, setOnFocusOut, setOnFormData, setOnGotPointerCapture, setOnInput, setOnInvalid, setOnKeyDown, setOnKeyPressed, setOnKeyUp, setOnLostPointerCapture, setOnMouseDown, setOnMouseEnter, setOnMouseLeave, setOnMouseMove, setOnMouseOut, setOnMouseOutChangeClass, setOnMouseOutChangeStyle, setOnMouseOutChangeStyle, setOnMouseOver, setOnMouseOverChangeClass, setOnMouseOverChangeStyle, setOnMouseOverChangeStyle, setOnMouseOverShow, setOnMouseUp, setOnPageLoad, setOnPaste, setOnPointerCancel, setOnPointerDown, setOnPointerEnter, setOnPointerLeave, setOnPointerMove, setOnPointerOut, setOnPointerOver, setOnPointerUp, setOnResize, setOnScroll, setOnScrollEnd, setOnSelect, setOnSelectionChange, setOnSelectStart, setOnToggle, setOnTouchCancel, setOnTouchEnd, setOnTouchMove, setOnTouchStart, setOnTransitionCancel, setOnTransitionEnd, setOnTransitionRun, setOnTransitionStart, setOnWheel, setOnWindowResize, setPopover, setRole, setRole, setSpellCheck, setTabIndex, setTitle, setTooltipMethods inherited from class com.oorian.html.Element
addAttribute, addAttribute, addAttribute, addAttribute, addLineBreak, assignId, containsElement, containsElement, create, dispatchEvent, dispatchEvent, dispatchEvent, dispatchEvent, equals, excludeId, executeJs, executeJs, executeJs, getAccept, getAllElements, getAncestor, getAttribute, getAttributes, getComponent, getDir, getElement, getElementById, getElementCount, getElementCount, getElements, getElements, getElementsByComponentName, getElementsByTagName, getHtml, getId, getInnerHtml, getInnerHtml, getIs, getItemId, getItemProp, getItemRef, getItemType, getLang, getNextSibling, getPage, getParent, getPart, getPrevSibling, getSlot, getTagName, getTextContent, getUrl, hasAttribute, hasElements, isChildOf, isClosedTag, isCreated, isDescendantOf, isDescendantOf, isInitialized, isItemScope, isTranslate, onCallback, onCreated, onElementAdded, onElementRemoved, onHashChange, onHidden, onInitialized, onJsReturn, onPageLoaded, onPageUnloaded, onRefresh, onShown, onUpdated, onUserEvent, prewrite, recreate, refresh, refresh, registerAddition, registerListener, registerListener, registerListener, registerListener, registerListener, registerListener, registerListener, registerSubtraction, registerUpdate, removeAttribute, removeAttribute, removeFromParent, requestCallback, requestCallback, requestCallback, requestCallback, resetId, scrollTo, scrollToBottom, scrollToTop, self, sendCommand, sendUpdate, setAccept, setComponent, setDir, setDir, setId, setIs, setItemId, setItemProp, setItemRef, setItemScope, setItemType, setLang, setOnError, setOnLoad, setPage, setParent, setPart, setSlot, setTagName, setTranslate, toString, unregisterListener, update, updateAttributes
-
Constructor Details
-
Button
public Button()Constructs an empty<button>element with no text or type specified. -
Button
Constructs a<button>element with the specified text content.- Parameters:
text- The text to display on the button.
-
-
Method Details
-
setForm
Associates this element with a form element.Specifies the form this element belongs to using the form's ID. This is useful when the element is placed outside of its associated
<form>in the document.- Parameters:
formId- the ID of the form element to associate with- Returns:
- This element for method chaining.
-
setFormAction
Overrides the form's action URL when this button is used to submit.Only valid for buttons with type="submit".
If the URL starts with "/" (absolute path within the application), the servlet context path will be automatically prepended.
- Parameters:
url- The URL to submit the form data to.- Returns:
- this element for method chaining
-
setFormEncType
Sets the form encoding type override using theFormEncodingenum.- Parameters:
encoding- The encoding type.- Returns:
- This element for method chaining.
-
setFormEncType
Sets the formenctype attribute.Overrides the form's
enctypeattribute for this specific submit button. Used on<button>and<input>elements withtype="submit"ortype="image".- Parameters:
encoding- The encoding type for form submission.- Returns:
- This element for method chaining.
-
setFormMethod
Sets the form method override using theFormMethodenum.- Parameters:
formMethod- The HTTP method (GET or POST).- Returns:
- This element for method chaining.
-
setFormMethod
Sets the formmethod attribute.Overrides the form's
methodattribute for this specific submit button. Used on<button>and<input>elements withtype="submit"ortype="image".- Parameters:
formMethod- The HTTP method for form submission (get, post).- Returns:
- This element for method chaining.
-
setFormNoValidate
Sets the formnovalidate boolean attribute.Overrides the form's validation behavior for this specific submit button, bypassing constraint validation. Used on
<button>and<input>elements withtype="submit"ortype="image".- Parameters:
flag- True to skip form validation, false to remove.- Returns:
- This element for method chaining.
-
setFormTarget
Sets the form target override using theTargetenum.- Parameters:
target- The browsing context for form submission.- Returns:
- This element for method chaining.
-
setFormTarget
Sets the formtarget attribute.Overrides the form's
targetattribute for this specific submit button, specifying where to display the response. Used on<button>and<input>elements withtype="submit"ortype="image". Values include"_self","_blank","_parent", and"_top".- Parameters:
target- The browsing context for form submission.- Returns:
- This element for method chaining.
-
setName
Sets the name attribute.Specifies the name of the element, used as a key when submitting form data or for programmatic access.
- Parameters:
name- The name of the element.- Returns:
- This element for method chaining.
-
setType
Sets the type of this button.The type determines the button's behavior:
ButtonType.SUBMIT- Submits the form dataButtonType.RESET- Resets the form to initial valuesButtonType.BUTTON- No default behavior, used with JavaScript
- Parameters:
type- The button type.- Returns:
- this element for method chaining
-
setType
Sets the type of this button.- Parameters:
type- The button type as a string (e.g., "submit", "reset", "button").- Returns:
- this element for method chaining
-
setDisabled
Sets the disabled boolean attribute.Indicates that the element should be disabled, preventing user interaction and form submission. Used on
<button>,<fieldset>,<input>,<select>, and<textarea>elements. Disabled elements are typically rendered in a grayed-out style.- Overrides:
setDisabledin classVisualElement<T extends Button<T>>- Parameters:
disabled- True to disable, false to enable.- Returns:
- This element for method chaining.
-
setPopoverTarget
Sets the ID of the popover element that this button controls.- Parameters:
popoverTarget- The ID of the popover target element.- Returns:
- This element for method chaining.
-
setPopoverTargetAction
Sets the action to perform on the target popover element.Values include
"toggle"(default),"show", and"hide".- Parameters:
popoverTargetAction- The popover action (toggle, show, hide).- Returns:
- This element for method chaining.
-
setValue
Sets the value submitted with the form data when this button is used as the submitter.- Parameters:
value- The value for this button.- Returns:
- This element for method chaining.
-
getForm
Returns the form attribute value.The form attribute associates this element with a form element that is not its ancestor.
- Returns:
- The associated form ID, or
nullif not set.
-
getName
Returns the name attribute value.The name attribute specifies the name used to identify the element in form submissions.
- Returns:
- The name, or
nullif not set.
-
getFormAction
Returns the formaction attribute value.The formaction attribute overrides the
actionattribute of the parent form for this specific submit button. Used on<button type="submit">and<input type="submit">elements.- Returns:
- The form action URL, or
nullif not set.
-
getFormEncType
Returns the formenctype attribute value.The formenctype attribute overrides the
enctypeattribute of the parent form for this specific submit button. Used on<button type="submit">and<input type="submit">elements.- Returns:
- The form encoding type, or
nullif not set.
-
getFormMethod
Returns the formmethod attribute value.The formmethod attribute overrides the
methodattribute of the parent form for this specific submit button. Used on<button type="submit">and<input type="submit">elements. Values are"get","post", or"dialog".- Returns:
- The form method, or
nullif not set.
-
isFormNoValidate
protected boolean isFormNoValidate()Returns whether the formnovalidate attribute is set.The formnovalidate attribute overrides the
novalidateattribute of the parent form, bypassing constraint validation for this specific submit button. Used on<button type="submit">and<input type="submit">elements.- Returns:
trueif formnovalidate is present,falseotherwise.
-
getFormTarget
Returns the formtarget attribute value.The formtarget attribute overrides the
targetattribute of the parent form for this specific submit button. Used on<button type="submit">and<input type="submit">elements. Values include"_self","_blank","_parent", and"_top".- Returns:
- The form target, or
nullif not set.
-