Class InputChangeEvent


public class InputChangeEvent extends InputEvent
Event fired when the value of an input element changes.

This event is triggered during user interaction with input controls when the value changes but before the input is complete. Unlike InputCompleteEvent which fires when editing is finished (e.g., on blur or Enter key), InputChangeEvent fires continuously as the user types or modifies the input. This enables real-time validation, live search, character counting, and other interactive feedback.

Features:

  • Captures input value changes in real-time
  • Supports optional state object for additional context
  • Enables live validation and interactive UI updates
  • Provides both current value and custom state information

Usage: Handle this event through an InputListener to respond to input changes as they occur. Common use cases include live search, character counting, format validation, and real-time form feedback.


 public class SearchFieldHandler implements InputListener {
     @Override
     public void onEvent(InputChangeEvent event) {
         String searchTerm = event.getValue();
         if (searchTerm.length() >= 3) {
             // Trigger live search
             performLiveSearch(searchTerm);
         }
     }

     @Override
     public void onEvent(InputCompleteEvent event) {
         // Handle input completion
     }
 }
 
Since:
2016
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • InputChangeEvent

      public InputChangeEvent()
      Constructs a new InputChangeEvent with no initial value or state.

      This default constructor creates an empty event. The value and state can be set later if needed.

    • InputChangeEvent

      public InputChangeEvent(String value)
      Constructs a new InputChangeEvent with the specified value.

      This constructor creates an event with the current input value but no associated state object.

      Parameters:
      value - the current value of the input element
    • InputChangeEvent

      public InputChangeEvent(String value, String state)
      Constructs a new InputChangeEvent with the specified value and state.

      This constructor creates an event with both the current input value and an optional state string that can provide additional context such as previous values, metadata, or validation state.

      Parameters:
      value - the current value of the input element
      state - optional state providing additional context
  • Method Details

    • getValue

      public String getValue()
      Returns the current value of the input element.

      This is the value as it exists at the time the change event was fired.

      Returns:
      the current input value, or null if not set
    • getState

      public String getState()
      Returns the optional state object associated with this event.

      The state object can contain additional context about the input change, such as previous values, cursor position, validation status, or any other application-specific information.

      Returns:
      the state string, or null if not set
    • dispatchTo

      public void dispatchTo(InputListener listener)
      Dispatches this event to the specified listener.

      This method implements the visitor pattern to deliver the event to the appropriate handler method on the InputListener. It calls the listener's onEvent(InputChangeEvent) method.

      Specified by:
      dispatchTo in class Event<InputListener>
      Parameters:
      listener - the InputListener that will handle this event