Package org.patternfly.handler
package org.patternfly.handler
Common event handler interfaces used throughout PatternFly Java components.
This package defines functional interfaces for handling various component events in a type-safe manner.
All handlers follow a consistent pattern: they accept a DOM event, the component that triggered the event,
and event-specific data. Components register these handlers using on<Event>() methods.
Handler Interfaces
ComponentHandler- Generic handler accepting a componentChangeHandler- Handler for value change events with old and new valuesSelectHandler- Handler for selection events with selected stateMultiSelectHandler- Handler for multi-selection events with list of selected itemsToggleHandler- Handler for expand/collapse toggle eventsCloseHandler- Handler for close/dismiss eventsResizeHandler- Handler for resize events with dimensions
Usage Examples
Change Handler
Handle value changes in form components:
TextInput input = textInput("username")
.onChange((event, component, value) -> {
console.log("Username changed to: " + value);
validateUsername(value);
});
Selection Handler
Respond to selection events in lists and tables:
DataList<User> dataList = dataList(dataProvider)
.onSelect((event, item, selected) -> {
console.log("User " + item.name() + " selected: " + selected);
});
Toggle Handler
Handle expand/collapse state in expandable components:
Drawer drawer = drawer()
.onToggle((event, component, expanded) -> {
console.log("Drawer expanded: " + expanded);
if (expanded) {
loadDrawerContent();
}
});
Close Handler
Perform cleanup when components are closed:
Alert alert = alert("Success", "Operation completed")
.onClose((event, component) -> {
console.log("Alert dismissed");
removeFromDOM(component);
});
Handler Registration Pattern
Components follow a consistent pattern for registering handlers. Methods are named on<Event>() and
return the component to enable method chaining:
Switch switch_ = switch_("enable-feature")
.value(false)
.onChange((e, c, value) -> console.log("Switch: " + value))
.onToggle((e, c, checked) -> updateFeatureState(checked));
Functional Interface Benefits
All handler interfaces are marked with @FunctionalInterface, enabling:
- Lambda expressions for concise event handling
- Method references for even more compact code
- Type safety with compile-time checking
- Clear IDE support with parameter hints
- See Also:
-
InterfacesClassDescriptionChangeHandler<C,
T> Functional interface for handling change events.CloseHandler<C>MultiSelectHandler<C,T> Functional interface for handling resize.