public final class Events extends Object
Collection of utility methods for the JSF API with respect to working with system and phase events.
Some examples:
// Add a callback to the current view which should run during every after phase of the render response on same view. Events.subscribeToViewAfterPhase(PhaseId.RENDER_RESPONSE, () -> { // ... });
// Add a callback to the current request which should run during before phase of the render response on current request. Events.subscribeToRequestBeforePhase(PhaseId.RENDER_RESPONSE, () -> { // ... });
// Add a callback to the current view which should run during the pre render view event. Events.subscribeToViewEvent(PreRenderViewEvent.class, () -> { // ... });
Note that you can specify any phase ID or system event to your choice.
CallbackPhaseListener
Modifier and Type | Method and Description |
---|---|
static void |
addRequestPhaseListener(jakarta.faces.event.PhaseListener listener)
Adds the given phase listener to the current request.
|
static void |
addViewPhaseListener(jakarta.faces.event.PhaseListener listener)
Adds the given phase listener to the current view.
|
static void |
subscribeToApplicationEvent(Class<? extends jakarta.faces.event.SystemEvent> type,
Callback.SerializableVoid callback)
Subscribe the given callback to the current application that get invoked every time when the given
system event type is published in the current application.
|
static void |
subscribeToApplicationEvent(Class<? extends jakarta.faces.event.SystemEvent> type,
Callback.SerializableWithArgument<jakarta.faces.event.SystemEvent> callback)
Subscribe the given callback to the current application that get invoked every time when the given
system event type is published in the current application.
|
static void |
subscribeToApplicationEvent(Class<? extends jakarta.faces.event.SystemEvent> type,
jakarta.faces.event.SystemEventListener listener)
Subscribe the given system event listener to the current application that get invoked every time when the given
system event type is published in the current application.
|
static void |
subscribeToRequestAfterPhase(jakarta.faces.event.PhaseId phaseId,
Consumer<jakarta.faces.event.PhaseEvent> callback)
Subscribe the given callback instance to the current request that get invoked after given phase ID.
|
static void |
subscribeToRequestAfterPhase(jakarta.faces.event.PhaseId phaseId,
Runnable callback)
Subscribe the given callback instance to the current request that get invoked after given phase ID.
|
static void |
subscribeToRequestBeforePhase(jakarta.faces.event.PhaseId phaseId,
Consumer<jakarta.faces.event.PhaseEvent> callback)
Subscribe the given callback instance to the current request that get invoked before given phase ID.
|
static void |
subscribeToRequestBeforePhase(jakarta.faces.event.PhaseId phaseId,
Runnable callback)
Subscribe the given callback instance to the current request that get invoked before given phase ID.
|
static void |
subscribeToRequestComponentEvent(jakarta.faces.component.UIComponent component,
Class<? extends jakarta.faces.event.ComponentSystemEvent> type,
Consumer<jakarta.faces.event.ComponentSystemEvent> callback)
Subscribe the given callback instance to the given component that get invoked only in the current request when
the given component system event type is published on the given component.
|
static void |
subscribeToViewAfterPhase(jakarta.faces.event.PhaseId phaseId,
Consumer<jakarta.faces.event.PhaseEvent> callback)
Subscribe the given callback instance to the current view that get invoked every time after given phase ID.
|
static void |
subscribeToViewAfterPhase(jakarta.faces.event.PhaseId phaseId,
Runnable callback)
Subscribe the given callback instance to the current view that get invoked every time after given phase ID.
|
static void |
subscribeToViewBeforePhase(jakarta.faces.event.PhaseId phaseId,
Consumer<jakarta.faces.event.PhaseEvent> callback)
Subscribe the given callback instance to the current view that get invoked every time before given phase ID.
|
static void |
subscribeToViewBeforePhase(jakarta.faces.event.PhaseId phaseId,
Runnable callback)
Subscribe the given callback instance to the current view that get invoked every time before given phase ID.
|
static void |
subscribeToViewEvent(Class<? extends jakarta.faces.event.SystemEvent> type,
Callback.SerializableVoid callback)
Subscribe the given callback to the current view that get invoked every time when the given
system event type is published on the current view.
|
static void |
subscribeToViewEvent(Class<? extends jakarta.faces.event.SystemEvent> type,
Callback.SerializableWithArgument<jakarta.faces.event.SystemEvent> callback)
Subscribe the given callback to the current view that get invoked every time when the given
system event type is published on the current view.
|
static void |
subscribeToViewEvent(Class<? extends jakarta.faces.event.SystemEvent> type,
jakarta.faces.event.SystemEventListener listener)
Subscribe the given system event listener to the current view that get invoked every time when the given
system event type is published on the current view.
|
static void |
unsubscribeFromComponentEvent(jakarta.faces.component.UIComponent component,
Class<? extends jakarta.faces.event.SystemEvent> event,
jakarta.faces.event.ComponentSystemEventListener listener)
Unsubscribe the given event listener on the given event from the given component.
|
public static void subscribeToApplicationEvent(Class<? extends jakarta.faces.event.SystemEvent> type, jakarta.faces.event.SystemEventListener listener)
type
- The system event type to be observed.listener
- The system event listener to be subscribed.Application.subscribeToEvent(Class, SystemEventListener)
public static void subscribeToApplicationEvent(Class<? extends jakarta.faces.event.SystemEvent> type, Callback.SerializableVoid callback)
type
- The system event type to be observed.callback
- The callback to be invoked.subscribeToApplicationEvent(Class, SystemEventListener)
public static void subscribeToApplicationEvent(Class<? extends jakarta.faces.event.SystemEvent> type, Callback.SerializableWithArgument<jakarta.faces.event.SystemEvent> callback)
type
- The system event type to be observed.callback
- The callback to be invoked.subscribeToApplicationEvent(Class, SystemEventListener)
public static void subscribeToViewEvent(Class<? extends jakarta.faces.event.SystemEvent> type, jakarta.faces.event.SystemEventListener listener)
type
- The system event type to be observed.listener
- The system event listener to be subscribed.UIViewRoot.subscribeToViewEvent(Class, SystemEventListener)
public static void subscribeToViewEvent(Class<? extends jakarta.faces.event.SystemEvent> type, Callback.SerializableVoid callback)
type
- The system event type to be observed.callback
- The callback to be invoked.subscribeToViewEvent(Class, SystemEventListener)
public static void subscribeToViewEvent(Class<? extends jakarta.faces.event.SystemEvent> type, Callback.SerializableWithArgument<jakarta.faces.event.SystemEvent> callback)
type
- The system event type to be observed.callback
- The callback to be invoked.subscribeToViewEvent(Class, SystemEventListener)
public static void addViewPhaseListener(jakarta.faces.event.PhaseListener listener)
addRequestPhaseListener(PhaseListener)
is that the given phase listener is invoked
during every (postback) request on the same view instead of only during the current request.listener
- The phase listener to be added to the current view.UIViewRoot.addPhaseListener(PhaseListener)
public static void subscribeToViewBeforePhase(jakarta.faces.event.PhaseId phaseId, Runnable callback)
phaseId
- The phase ID to be observed.callback
- The callback to be invoked.addViewPhaseListener(PhaseListener)
public static void subscribeToViewBeforePhase(jakarta.faces.event.PhaseId phaseId, Consumer<jakarta.faces.event.PhaseEvent> callback)
phaseId
- The phase ID to be observed.callback
- The callback to be invoked.addViewPhaseListener(PhaseListener)
public static void subscribeToViewAfterPhase(jakarta.faces.event.PhaseId phaseId, Runnable callback)
phaseId
- The phase ID to be observed.callback
- The callback to be invoked.addViewPhaseListener(PhaseListener)
public static void subscribeToViewAfterPhase(jakarta.faces.event.PhaseId phaseId, Consumer<jakarta.faces.event.PhaseEvent> callback)
phaseId
- The phase ID to be observed.callback
- The callback to be invoked.addViewPhaseListener(PhaseListener)
public static void subscribeToRequestComponentEvent(jakarta.faces.component.UIComponent component, Class<? extends jakarta.faces.event.ComponentSystemEvent> type, Consumer<jakarta.faces.event.ComponentSystemEvent> callback)
UIComponent.subscribeToEvent(Class, ComponentSystemEventListener)
is that this listener is request
scoped instead of view scoped as component system event listeners are by default saved in JSF state and thus
inherently view scoped.component
- The component to subscribe the given callback instance to.type
- The system event type to be observed.callback
- The callback to be invoked.UIComponent.subscribeToEvent(Class, ComponentSystemEventListener)
,
unsubscribeFromComponentEvent(UIComponent, Class, ComponentSystemEventListener)
public static void addRequestPhaseListener(jakarta.faces.event.PhaseListener listener)
addViewPhaseListener(PhaseListener)
is that the given phase listener is invoked
only during the current request instead of during every (postback) request on the same view.listener
- The phase listener to be added to the current request.CallbackPhaseListener
public static void subscribeToRequestBeforePhase(jakarta.faces.event.PhaseId phaseId, Runnable callback)
phaseId
- The phase ID to be observed.callback
- The callback to be invoked.addRequestPhaseListener(PhaseListener)
public static void subscribeToRequestBeforePhase(jakarta.faces.event.PhaseId phaseId, Consumer<jakarta.faces.event.PhaseEvent> callback)
phaseId
- The phase ID to be observed.callback
- The callback to be invoked.addRequestPhaseListener(PhaseListener)
public static void subscribeToRequestAfterPhase(jakarta.faces.event.PhaseId phaseId, Runnable callback)
phaseId
- The phase ID to be observed.callback
- The callback to be invoked.addRequestPhaseListener(PhaseListener)
public static void subscribeToRequestAfterPhase(jakarta.faces.event.PhaseId phaseId, Consumer<jakarta.faces.event.PhaseEvent> callback)
phaseId
- The phase ID to be observed.callback
- The callback to be invoked.addRequestPhaseListener(PhaseListener)
public static void unsubscribeFromComponentEvent(jakarta.faces.component.UIComponent component, Class<? extends jakarta.faces.event.SystemEvent> event, jakarta.faces.event.ComponentSystemEventListener listener)
UIComponent.unsubscribeFromEvent(Class, ComponentSystemEventListener)
for this, but this wouldn't work
when executed inside ComponentSystemEventListener.processEvent(jakarta.faces.event.ComponentSystemEvent)
,
as it would otherwise end up in a ConcurrentModificationException
while JSF is iterating over all
system event listeners. The trick is to perform the unsubscribe during the after phase of the current request
phase #subscribeToRequestAfterPhase(PhaseId, org.omnifaces.util.Callback.Void)
.component
- The component to unsubscribe the given event listener from.event
- The event associated with the given event listener.listener
- The event listener to be unsubscribed from the given component.IllegalStateException
- When this method is invoked during render response phase, because it would be too
late to remove it from the view state.#subscribeToRequestAfterPhase(PhaseId, org.omnifaces.util.Callback.Void)
,
UIComponent.unsubscribeFromEvent(Class, ComponentSystemEventListener)
Copyright © 2012–2020 OmniFaces. All rights reserved.