Class FocusOutEvent


public class FocusOutEvent extends FocusEvent
Event fired when an HTML element loses keyboard focus.

This event is triggered when a user moves focus away from an interactive element, either by focusing on another element, clicking outside focusable areas, or navigating away via keyboard. Focus-out events are commonly used to trigger field validation, save form data, remove visual highlights, and clean up temporary UI states.

Features:

  • Indicates when an element loses keyboard focus
  • Provides access to the previously focused element through getSource()
  • Dispatches to FocusListener implementations
  • Supports blur-based validation and state management

Usage: Handle this event through a FocusListener to respond when elements lose focus. Common use cases include validating field input, removing active styling, or persisting user changes.


 public class FormFieldHandler implements FocusListener {
     @Override
     public void onEvent(FocusInEvent event) {
         // Handle focus in
     }

     @Override
     public void onEvent(FocusOutEvent event) {
         Element field = event.getSource();
         field.removeStyleClass("focused");
         // Validate the field when user moves away
         if (!isValid(field.getValue())) {
             field.addStyleClass("error");
             showValidationMessage(field);
         }
     }
 }
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • FocusOutEvent

      public FocusOutEvent()
  • Method Details

    • dispatchTo

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

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