Class UserEvent


public class UserEvent extends ClientEvent<UserEventListener>
Event representing custom user-defined actions and interactions.

UserEvent provides a flexible mechanism for handling custom client-side events that don't fit into the standard event categories (focus, keyboard, input, form). This event type allows applications to define and process application-specific user interactions with custom parameter sets, making it ideal for button clicks, custom controls, menu selections, and other domain-specific actions.

Features:

  • Flexible event type for custom user interactions
  • Supports arbitrary parameters through Parameters collection
  • Can represent any application-specific user action
  • Integrates with UserEventListener for type-safe handling

Usage: Use UserEvent for custom application events that don't correspond to standard DOM events. Create the event, add relevant parameters, and dispatch it through a UserEventListener. This pattern is commonly used for button actions, custom widget interactions, and business-specific operations.


 public class OrderButtonHandler implements UserEventListener {
     @Override
     public void onEvent(UserEvent event) {
         Parameters params = event.getParameters();
         String action = params.getString("action");
         String orderId = params.getString("orderId");

         switch (action) {
             case "approve":
                 approveOrder(orderId);
                 break;
             case "reject":
                 rejectOrder(orderId);
                 break;
             case "view":
                 viewOrderDetails(orderId);
                 break;
         }
     }
 }
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • UserEvent

      public UserEvent()
      Constructs a new UserEvent with an empty parameter set.

      Creates a user event with no initial parameters. Parameters can be added after construction using the addParameter and addParameters methods.

  • Method Details

    • addParameter

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

      This method allows adding individual parameter values to the event's parameter collection. Use this to pass custom data from the client side to the event handler. 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 user event.

      This method allows adding an array of values for a single parameter, which is useful for passing multiple related values or list data.

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

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

      The returned Parameters object contains all custom parameter names and their associated values that were added to this event. Event handlers use this to access the event's data.

      Returns:
      the Parameters object containing all event data
    • dispatchTo

      public final void dispatchTo(UserEventListener 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 UserEventListener. It calls the listener's onEvent(UserEvent) method. This method is marked final to prevent subclasses from altering the dispatch mechanism.

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