Class Fieldset<T extends Fieldset<T>>


public class Fieldset<T extends Fieldset<T>> extends StyledContainerElement<T>
Represents the HTML <fieldset> element for grouping related form controls.

The Fieldset class provides a Java representation of the HTML fieldset element, which groups related form elements together with a visible border and optional legend caption. Fieldsets improve form organization, accessibility, and visual presentation.

Features:

  • Visual grouping of related form controls with border
  • Legend support for group caption/title
  • Form association for fieldsets outside form boundaries
  • Named fieldsets for programmatic access
  • Improved semantic structure for forms
  • Enhanced accessibility for screen readers

Usage Example:


 // Create a fieldset with legend
 Fieldset personalInfo = new Fieldset("Personal Information");
 personalInfo.setName("personal");
 personalInfo.addElement(new Label("First Name:"));
 personalInfo.addElement(new TextInput("firstName"));
 personalInfo.addElement(new Label("Last Name:"));
 personalInfo.addElement(new TextInput("lastName"));

 // Create a fieldset with Legend object
 Fieldset contactInfo = new Fieldset();
 contactInfo.setLegend(new Legend("Contact Information"));
 contactInfo.addElement(new Label("Email:"));
 contactInfo.addElement(new TextInput("email"));

 // Create a fieldset associated with a specific form
 Fieldset addressInfo = new Fieldset("Address");
 addressInfo.setForm("registrationForm");
 addressInfo.addElement(new Label("Street:"));
 addressInfo.addElement(new TextInput("street"));
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • Fieldset

      public Fieldset()
      Constructs a new fieldset element without a legend.
    • Fieldset

      public Fieldset(String legend)
      Constructs a new fieldset element with the specified legend text.
      Parameters:
      legend - The text to display in the fieldset's legend.
  • Method Details

    • setDisabled

      public final T setDisabled(boolean disabled)
      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:
      setDisabled in class VisualElement<T extends Fieldset<T>>
      Parameters:
      disabled - True to disable, false to enable.
      Returns:
      This element for method chaining.
    • setForm

      public final T setForm(String formId)
      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.
    • setLegend

      public final void setLegend(Legend legend)
      Sets the legend for this fieldset using a Legend element.
      Parameters:
      legend - The Legend element to use as the fieldset's caption.
    • setLegend

      public final void setLegend(String text)
      Sets the legend for this fieldset using text.

      Creates a new Legend element with the specified text and adds it to the fieldset.

      Parameters:
      text - The text to display in the legend.
    • setName

      public final T setName(String text)
      Sets the name attribute.

      Specifies the name of the element, used as a key when submitting form data or for programmatic access.

      Parameters:
      text - The name of the element.
      Returns:
      This element for method chaining.
    • getForm

      protected String 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 null if not set.
    • setFormAction

      protected T setFormAction(String formAction)
      Sets the formaction attribute.

      Overrides the form's action attribute for this specific submit button. Used on <button> and <input> elements with type="submit" or type="image". The value specifies the URL to submit the form data to.

      If the URL starts with "/" (absolute path within the application), the servlet context path will be automatically prepended.

      Parameters:
      formAction - The URL for form submission.
      Returns:
      This element for method chaining.
    • setFormEncType

      protected T setFormEncType(String formEncType)
      Sets the formenctype attribute.

      Overrides the form's enctype attribute for this specific submit button. Used on <button> and <input> elements with type="submit" or type="image".

      Parameters:
      formEncType - The encoding type for form submission.
      Returns:
      This element for method chaining.
    • setFormEncType

      protected T setFormEncType(FormEncoding formEncType)
      Sets the form encoding type override using the FormEncoding enum.
      Parameters:
      formEncType - The encoding type.
      Returns:
      This element for method chaining.
    • setFormMethod

      protected T setFormMethod(String formMethod)
      Sets the formmethod attribute.

      Overrides the form's method attribute for this specific submit button. Used on <button> and <input> elements with type="submit" or type="image".

      Parameters:
      formMethod - The HTTP method for form submission (get, post).
      Returns:
      This element for method chaining.
    • setFormMethod

      protected T setFormMethod(FormMethod formMethod)
      Sets the form method override using the FormMethod enum.
      Parameters:
      formMethod - The HTTP method (GET or POST).
      Returns:
      This element for method chaining.
    • setFormNoValidate

      protected T setFormNoValidate(boolean formNoValidate)
      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 with type="submit" or type="image".

      Parameters:
      formNoValidate - True to skip form validation, false to remove.
      Returns:
      This element for method chaining.
    • setFormTarget

      protected T setFormTarget(String formTarget)
      Sets the formtarget attribute.

      Overrides the form's target attribute for this specific submit button, specifying where to display the response. Used on <button> and <input> elements with type="submit" or type="image". Values include "_self", "_blank", "_parent", and "_top".

      Parameters:
      formTarget - The browsing context for form submission.
      Returns:
      This element for method chaining.
    • setFormTarget

      protected T setFormTarget(Target formTarget)
      Sets the form target override using the Target enum.
      Parameters:
      formTarget - The browsing context for form submission.
      Returns:
      This element for method chaining.
    • getName

      protected String getName()
      Returns the name attribute value.

      The name attribute specifies the name used to identify the element in form submissions.

      Returns:
      The name, or null if not set.
    • getFormAction

      protected String getFormAction()
      Returns the formaction attribute value.

      The formaction attribute overrides the action attribute 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 null if not set.
    • getFormEncType

      protected String getFormEncType()
      Returns the formenctype attribute value.

      The formenctype attribute overrides the enctype attribute 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 null if not set.
    • getFormMethod

      protected String getFormMethod()
      Returns the formmethod attribute value.

      The formmethod attribute overrides the method attribute 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 null if not set.
    • isFormNoValidate

      protected boolean isFormNoValidate()
      Returns whether the formnovalidate attribute is set.

      The formnovalidate attribute overrides the novalidate attribute of the parent form, bypassing constraint validation for this specific submit button. Used on <button type="submit"> and <input type="submit"> elements.

      Returns:
      true if formnovalidate is present, false otherwise.
    • getFormTarget

      protected String getFormTarget()
      Returns the formtarget attribute value.

      The formtarget attribute overrides the target attribute 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 null if not set.