Class Checkbox<T extends Checkbox<T>>


public class Checkbox<T extends Checkbox<T>> extends Input<T>
HTML checkbox input element for boolean selection.

This class extends Input to provide a checkbox control that allows users to select or deselect an option. The checkbox maintains its checked state and provides methods for programmatic control and user interaction handling.

Features:

  • Boolean on/off selection
  • Programmatic check/uncheck control
  • Checked state tracking
  • Click event handling with state callback
  • Multiple constructors for flexible initialization

Usage:

 Checkbox agree = new Checkbox("agree", "yes");
 agree.setChecked(true);
 if (agree.isChecked()) {
     // Process agreement
 }
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • Checkbox

      public Checkbox()
      Creates a new Checkbox element.
    • Checkbox

      public Checkbox(String name, Object value)
      Creates a new Checkbox with the specified name and value.
      Parameters:
      name - The name attribute for form submission.
      value - The value submitted when the checkbox is checked.
    • Checkbox

      public Checkbox(String name, String value)
      Creates a new Checkbox with the specified name and string value.
      Parameters:
      name - The name attribute for form submission.
      value - The string value submitted when the checkbox is checked.
    • Checkbox

      public Checkbox(Object value)
      Creates a new Checkbox with the specified value.
      Parameters:
      value - The value submitted when the checkbox is checked.
    • Checkbox

      public Checkbox(String value)
      Creates a new Checkbox with the specified string value.
      Parameters:
      value - The string value submitted when the checkbox is checked.
  • Method Details

    • setChecked

      public final T setChecked(boolean checked)
      Sets the checked state of this checkbox.
      Overrides:
      setChecked in class InputElement<T extends Checkbox<T>>
      Parameters:
      checked - true to check this checkbox, false to uncheck it.
      Returns:
      This element for method chaining.
    • check

      public final void check()
      Checks this checkbox and updates the DOM.
    • uncheck

      public final void uncheck()
      Unchecks this checkbox and updates the DOM.
    • isChecked

      public final boolean isChecked()
      Returns whether this checkbox is currently checked.
      Returns:
      true if this checkbox is checked, false otherwise.
    • onClicked

      public final void onClicked(boolean checked)
      Called by the event handler when the checkbox is clicked, updating the checked state if changed.
      Parameters:
      checked - The new checked state from the client.
    • onClicked

      public void onClicked()
      Callback invoked after the checkbox click is processed. Override to handle click events.