Class TextArea<T extends TextArea<T>>


public class TextArea<T extends TextArea<T>> extends InputElement<T>
Represents the HTML <textarea> element for multi-line text input.

The TextArea class provides a Java representation of the HTML textarea element, which creates a multi-line text input control. It's ideal for collecting longer text content such as comments, descriptions, messages, or any other text that may span multiple lines.

Features:

  • Configurable rows and columns for text area dimensions
  • Text content management with getValue/setValue
  • Input completion event handling with optional value change filtering
  • Support for Enter key as completion trigger
  • Reset capability to clear content
  • Named textarea for form submission
  • Extensible onInputComplete hook for custom handling

Usage Example:


 // Create a basic textarea
 TextArea comments = new TextArea("comments");
 comments.setRows(5);
 comments.setCols(50);
 comments.setText("Enter your comments here...");

 // Create a textarea with input completion handling
 TextArea description = new TextArea();
 description.setName("description");
 description.setRows(10);
 description.setIgnoreValueNonchanges(false); // Fire events even if value unchanged
 description.registerListener(new InputCompleteListener() {
     public void onEvent(InputCompleteEvent event) {
         String text = event.getValue();
         // Process the completed input
     }
 }, InputCompleteEvent.class);

 // Create a textarea that completes on Enter key
 TextArea chatInput = new TextArea();
 chatInput.setChangeOnEnter();
 chatInput.setRows(3);
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • TextArea

      public TextArea()
      Constructs a new textarea element.
    • TextArea

      public TextArea(String name)
      Constructs a new textarea element with the specified name.
      Parameters:
      name - The name attribute for form submission.
  • Method Details

    • setCols

      public final T setCols(int cols)
      Sets the visible width of the textarea in average character widths.
      Parameters:
      cols - the number of visible character columns
      Returns:
      this element for method chaining
    • setRows

      public T setRows(int rows)
      Sets the rows attribute.

      Specifies the number of visible text lines for the text area. Used on <textarea> elements.

      Parameters:
      rows - The number of visible text lines.
      Returns:
      This element for method chaining.
    • setWrap

      public final T setWrap(String wrap)
      Sets how the textarea text should be wrapped on form submission.

      Values include "hard" (inserts line breaks to match column width), "soft" (no line breaks inserted), and "off" (no wrapping).

      Parameters:
      wrap - the wrap mode ("hard", "soft", or "off")
      Returns:
      this element for method chaining
    • setText

      public final void setText(String text)
      Sets the text content of the textarea.
      Overrides:
      setText in class Element<T extends TextArea<T>>
      Parameters:
      text - The text to display in the textarea.
    • setIgnoreValueNonchanges

      public final T setIgnoreValueNonchanges(boolean ignoreValueNonchanges)
      Sets whether to ignore input completion events when the value hasn't changed.

      When true (the default), InputCompleteEvent is only sent when the value actually changed during the focus session. When false, the event is sent on every blur regardless of whether the value changed.

      Parameters:
      ignoreValueNonchanges - true to suppress events when value unchanged, false to fire events on every blur.
      Returns:
      this element for method chaining
    • setChangeOnEnter

      public final void setChangeOnEnter()
      Enables input completion on Enter key press.
    • getText

      public final String getText()
      Returns the text content of the textarea.
      Returns:
      The current text value.
    • getRows

      protected int getRows()
      Returns the rows attribute value.

      The rows attribute specifies the visible height of a text area in lines. Used on <textarea> elements. The default value is typically 2.

      Returns:
      The number of rows, or 0 if not set.
    • reset

      public boolean reset()
      Resets the textarea content to empty.
      Overrides:
      reset in class InputElement<T extends TextArea<T>>
      Returns:
      true if the content was changed, false otherwise.
    • inputComplete

      public final void inputComplete()
      Called when input is completed in the textarea.

      Dispatches an InputCompleteEvent and calls the onInputComplete() hook.

    • onInputComplete

      protected void onInputComplete()
      Hook method called when input is completed.

      Override this method to handle input completion events.

    • getInnerHtml

      protected void getInnerHtml(StringBuilder sb)
      Description copied from class: Element
      Appends the inner HTML of this element to the specified StringBuilder.

      Iterates through all child elements and appends their HTML representations to the builder. Uses a synchronized copy of the children list to avoid concurrent modification issues.

      Overrides:
      getInnerHtml in class Element<T extends TextArea<T>>
      Parameters:
      sb - The StringBuilder to append the inner HTML to.