Class FormEvent


public class FormEvent extends ClientEvent<FormListener>
Event fired when a form is submitted from the client side.

This event captures form submission actions and provides access to all form field values through a Parameters object. FormEvent is central to processing user input from HTML forms, enabling server-side validation, data persistence, and business logic execution in response to form submissions.

Features:

  • Captures all form field values in a Parameters collection
  • Supports single and multi-value parameters (e.g., checkboxes, multi-selects)
  • Provides methods to add additional parameters dynamically
  • Integrates with FormListener for type-safe event handling

Usage: Handle this event through a FormListener to process form submissions. Access field values through the Parameters object, validate input, and execute application logic based on the submitted data.


 public class RegistrationFormHandler implements FormListener {
     @Override
     public void onEvent(FormEvent event) {
         Parameters params = event.getParameters();
         String username = params.getString("username");
         String email = params.getString("email");
         String[] interests = params.getStrings("interests");

         // Validate and process form data
         if (validateInput(username, email)) {
             createUserAccount(username, email, interests);
         }
     }
 }
 
Since:
2015
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • FormEvent

      public FormEvent(Parameters parameters)
      Constructs a new FormEvent with the specified parameters.

      Creates a defensive copy of the provided parameters to ensure immutability of the original parameter set while allowing modification of the event's parameter collection.

      Parameters:
      parameters - the form parameters containing field names and values
  • Method Details

    • addParameter

      public void addParameter(String name, String value)
      Adds a single parameter value to this form event.

      This method allows dynamic addition of parameter values, useful for adding computed or derived values based on the original form submission. If the parameter already exists, this adds an additional value to that parameter's value array.

      Parameters:
      name - the parameter name
      value - the parameter value to add
    • addParameters

      public void addParameters(String name, String[] values)
      Adds multiple values for a parameter to this form event.

      This method allows adding an array of values for a single parameter, which is useful for multi-select fields, checkbox groups, or other controls that can have multiple values.

      Parameters:
      name - the parameter name
      values - the array of parameter values to add
    • getParameters

      public Parameters getParameters()
      Returns the parameters collection for this form event.

      The returned Parameters object contains all form field names and their associated values from the form submission, plus any additional parameters added through the add methods.

      Returns:
      the Parameters object containing all form data
    • dispatchTo

      public void dispatchTo(FormListener 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 FormListener. It calls the listener's onEvent(FormEvent) method.

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