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, new Callback.Void() { @Override public void invoke() { // ... } });
// 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, new Callback.Void() { @Override public void invoke() { // ... } });
// Add a callback to the current view which should run during the pre render view event. Events.subscribeToViewEvent(PreRenderViewEvent.class, new Callback.SerializableVoid() { @Override public void invoke() { // ... } });
Note that you can specify any phase ID or system event to your choice.
Modifier and Type | Method and Description |
---|---|
static void |
addRequestPhaseListener(PhaseListener listener)
Adds the given phase listener to the current request.
|
static void |
addViewPhaseListener(PhaseListener listener)
Adds the given phase listener to the current view.
|
static void |
subscribeToApplicationEvent(Class<? extends 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 SystemEvent> type,
Callback.SerializableWithArgument<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 SystemEvent> type,
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(PhaseId phaseId,
Callback.Void callback)
Subscribe the given callback instance to the current request that get invoked after given phase ID.
|
static void |
subscribeToRequestAfterPhase(PhaseId phaseId,
Callback.WithArgument<PhaseEvent> callback)
Subscribe the given callback instance to the current request that get invoked after given phase ID.
|
static void |
subscribeToRequestBeforePhase(PhaseId phaseId,
Callback.Void callback)
Subscribe the given callback instance to the current request that get invoked before given phase ID.
|
static void |
subscribeToRequestBeforePhase(PhaseId phaseId,
Callback.WithArgument<PhaseEvent> callback)
Subscribe the given callback instance to the current request that get invoked before given phase ID.
|
static void |
subscribeToRequestComponentEvent(UIComponent component,
Class<? extends ComponentSystemEvent> type,
Callback.WithArgument<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(PhaseId phaseId,
Callback.Void callback)
Subscribe the given callback instance to the current view that get invoked every time after given phase ID.
|
static void |
subscribeToViewAfterPhase(PhaseId phaseId,
Callback.WithArgument<PhaseEvent> callback)
Subscribe the given callback instance to the current view that get invoked every time after given phase ID.
|
static void |
subscribeToViewBeforePhase(PhaseId phaseId,
Callback.Void callback)
Subscribe the given callback instance to the current view that get invoked every time before given phase ID.
|
static void |
subscribeToViewBeforePhase(PhaseId phaseId,
Callback.WithArgument<PhaseEvent> callback)
Subscribe the given callback instance to the current view that get invoked every time before given phase ID.
|
static void |
subscribeToViewEvent(Class<? extends 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 SystemEvent> type,
Callback.SerializableWithArgument<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 SystemEvent> type,
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(UIComponent component,
Class<? extends SystemEvent> event,
ComponentSystemEventListener listener)
Unsubscribe the given event listener on the given event from the given component.
|
public static void subscribeToApplicationEvent(Class<? extends SystemEvent> type, 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 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 SystemEvent> type, Callback.SerializableWithArgument<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 SystemEvent> type, 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 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 SystemEvent> type, Callback.SerializableWithArgument<SystemEvent> callback)
type
- The system event type to be observed.callback
- The callback to be invoked.subscribeToViewEvent(Class, SystemEventListener)
public static void addViewPhaseListener(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(PhaseId phaseId, Callback.Void callback)
phaseId
- The phase ID to be observed.callback
- The callback to be invoked.addViewPhaseListener(PhaseListener)
public static void subscribeToViewBeforePhase(PhaseId phaseId, Callback.WithArgument<PhaseEvent> callback)
phaseId
- The phase ID to be observed.callback
- The callback to be invoked.addViewPhaseListener(PhaseListener)
public static void subscribeToViewAfterPhase(PhaseId phaseId, Callback.Void callback)
phaseId
- The phase ID to be observed.callback
- The callback to be invoked.addViewPhaseListener(PhaseListener)
public static void subscribeToViewAfterPhase(PhaseId phaseId, Callback.WithArgument<PhaseEvent> callback)
phaseId
- The phase ID to be observed.callback
- The callback to be invoked.addViewPhaseListener(PhaseListener)
public static void subscribeToRequestComponentEvent(UIComponent component, Class<? extends ComponentSystemEvent> type, Callback.WithArgument<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(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(PhaseId phaseId, Callback.Void callback)
phaseId
- The phase ID to be observed.callback
- The callback to be invoked.addRequestPhaseListener(PhaseListener)
public static void subscribeToRequestBeforePhase(PhaseId phaseId, Callback.WithArgument<PhaseEvent> callback)
phaseId
- The phase ID to be observed.callback
- The callback to be invoked.addRequestPhaseListener(PhaseListener)
public static void subscribeToRequestAfterPhase(PhaseId phaseId, Callback.Void callback)
phaseId
- The phase ID to be observed.callback
- The callback to be invoked.addRequestPhaseListener(PhaseListener)
public static void subscribeToRequestAfterPhase(PhaseId phaseId, Callback.WithArgument<PhaseEvent> callback)
phaseId
- The phase ID to be observed.callback
- The callback to be invoked.addRequestPhaseListener(PhaseListener)
public static void unsubscribeFromComponentEvent(UIComponent component, Class<? extends SystemEvent> event, ComponentSystemEventListener listener)
UIComponent.unsubscribeFromEvent(Class, ComponentSystemEventListener)
for this, but this wouldn't work
when executed inside ComponentSystemEventListener.processEvent(javax.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–2015 OmniFaces. All rights reserved.