org.omnifaces.util
Class Events

java.lang.Object
  extended by org.omnifaces.util.Events

public final class Events
extends java.lang.Object

Collection of utility methods for the JSF API with respect to working with Faces events.

Author:
Arjan Tijms

Method Summary
static void addAfterPhaseListener(javax.faces.event.PhaseId phaseId, Callback.Void callback)
          Adds a phase listener to the current view that invokes the given callback every time after given phase.
static void addBeforePhaseListener(javax.faces.event.PhaseId phaseId, Callback.Void callback)
          Adds a phase listener to the current view that invokes the given callback every time before given phase ID.
static void addPhaseListener(javax.faces.event.PhaseListener phaseListener)
          Adds a phase listener to the current view root of the current faces context.
static javax.faces.event.PhaseListener createAfterPhaseListener(javax.faces.event.PhaseId phaseId, Callback.Void callback)
          Creates a phase listener that invokes the given callback every time after the given phase.
static javax.faces.event.PhaseListener createBeforePhaseListener(javax.faces.event.PhaseId phaseId, Callback.Void callback)
          Creates a phase listener that invokes the given callback every time before the given phase.
static void removeCallbackPhaseListener()
          Removes the one and only phase listener from callbacks by the global phase listener for the current request.
static void removePhaseListener(javax.faces.event.PhaseListener phaseListener)
          Removes a phase listener from the current view root of the current faces context.
static void setCallbackAfterPhaseListener(javax.faces.event.PhaseId phaseId, Callback.Void callback)
          Sets a phase listener for callback by a global phase listener during the current request that invokes the given callback every time after given phase ID.
static void setCallBackBeforePhaseListener(javax.faces.event.PhaseId phaseId, Callback.Void callback)
          Sets a phase listener for callback by a global phase listener during the current request that invokes the given callback every time before given phase ID.
static void setCallbackPhaseListener(javax.faces.event.PhaseListener phaseListener)
          Sets phase listener for callback by a global phase listener during the current request.
static void subscribeToEvent(java.lang.Class<? extends javax.faces.event.SystemEvent> type, javax.faces.event.SystemEventListener listener)
          Adds the given system event listener to the application that get invoked every time when the given system event type is published.
static void subscribeToViewEvent(java.lang.Class<? extends javax.faces.event.SystemEvent> type, Callback.Void callback)
          Install the callback instance referenced by argument listener into the UIViewRoot as a listener for events of type systemEventClass.
static void subscribeToViewEvent(java.lang.Class<? extends javax.faces.event.SystemEvent> type, javax.faces.event.SystemEventListener listener)
          Install the listener instance referenced by argument listener into the UIViewRoot as a listener for events of type systemEventClass.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addPhaseListener

public static void addPhaseListener(javax.faces.event.PhaseListener phaseListener)
Adds a phase listener to the current view root of the current faces context.

Parameters:
phaseListener - The phase listener to be added to the current view root of the current faces context.

removePhaseListener

public static void removePhaseListener(javax.faces.event.PhaseListener phaseListener)
Removes a phase listener from the current view root of the current faces context.

Parameters:
phaseListener - The phase listener to be removed from the current view root of the current faces context.

setCallbackPhaseListener

public static void setCallbackPhaseListener(javax.faces.event.PhaseListener phaseListener)
Sets phase listener for callback by a global phase listener during the current request.

This differs in a few subtle ways from addPhaseListener(PhaseListener). Namely, the phase listener registered here will be called via the global phase listener, which executes slightly earlier for its before phase and slightly later for its after phase as compared to phase listeners attached to the view root.

Additionally, a phase listener registered via this method will not become part of the view state, but will execute only once. Phase listeners attached to the view root will come back after each postback and have to be remove manually (in Mojarra this can be difficult due to the fact iterators over listeners are kept 'open' during each phase).

Note: at the moment only 1 callback phase listener per request can be set.

Parameters:
phaseListener - The phase listener to be set for callback during the current request.
Since:
1.2

removeCallbackPhaseListener

public static void removeCallbackPhaseListener()
Removes the one and only phase listener from callbacks by the global phase listener for the current request.

Since:
1.2

addBeforePhaseListener

public static void addBeforePhaseListener(javax.faces.event.PhaseId phaseId,
                                          Callback.Void callback)
Adds a phase listener to the current view that invokes the given callback every time before given phase ID.

Parameters:
phaseId - The phase ID to invoke the given callback every time before.
callback - The callback to be invoked every time before the given phase ID of the current view.

addAfterPhaseListener

public static void addAfterPhaseListener(javax.faces.event.PhaseId phaseId,
                                         Callback.Void callback)
Adds a phase listener to the current view that invokes the given callback every time after given phase.

Parameters:
phaseId - The phase ID to invoke the given callback every time after.
callback - The callback to be invoked every time after the given phase ID of the current view.

setCallBackBeforePhaseListener

public static void setCallBackBeforePhaseListener(javax.faces.event.PhaseId phaseId,
                                                  Callback.Void callback)
Sets a phase listener for callback by a global phase listener during the current request that invokes the given callback every time before given phase ID.

Parameters:
phaseId - The phase ID to invoke the given callback every time before.
callback - The callback to be invoked every time before the given phase ID of the current request.
Since:
1.2

setCallbackAfterPhaseListener

public static void setCallbackAfterPhaseListener(javax.faces.event.PhaseId phaseId,
                                                 Callback.Void callback)
Sets a phase listener for callback by a global phase listener during the current request that invokes the given callback every time after given phase ID.

Parameters:
phaseId - The phase ID to invoke the given callback every time after.
callback - The callback to be invoked every time after the given phase ID of the current request.
Since:
1.2

createBeforePhaseListener

public static javax.faces.event.PhaseListener createBeforePhaseListener(javax.faces.event.PhaseId phaseId,
                                                                        Callback.Void callback)
Creates a phase listener that invokes the given callback every time before the given phase.

Parameters:
phaseId - The phase ID to invoke the given callback every time before.
callback - The callback to be invoked every time before the given phase ID of the current view.
Returns:
A phase listener that invokes the given callback every time before the given phase.
Since:
1.2

createAfterPhaseListener

public static javax.faces.event.PhaseListener createAfterPhaseListener(javax.faces.event.PhaseId phaseId,
                                                                       Callback.Void callback)
Creates a phase listener that invokes the given callback every time after the given phase.

Parameters:
phaseId - The phase ID to invoke the given callback every time after.
callback - The callback to be invoked every time after the given phase ID of the current view.
Returns:
A phase listener that invokes the given callback every time after the given phase.
Since:
1.2

subscribeToEvent

public static void subscribeToEvent(java.lang.Class<? extends javax.faces.event.SystemEvent> type,
                                    javax.faces.event.SystemEventListener listener)
Adds the given system event listener to the application that get invoked every time when the given system event type is published.

Parameters:
type - The system event type to listen on.
listener - The system event listener to be invoked.
Since:
1.1

subscribeToViewEvent

public static void subscribeToViewEvent(java.lang.Class<? extends javax.faces.event.SystemEvent> type,
                                        javax.faces.event.SystemEventListener listener)
Install the listener instance referenced by argument listener into the UIViewRoot as a listener for events of type systemEventClass.

Parameters:
type - The system event type to listen on.
listener - The system event listener to be invoked.
Since:
1.2

subscribeToViewEvent

public static void subscribeToViewEvent(java.lang.Class<? extends javax.faces.event.SystemEvent> type,
                                        Callback.Void callback)
Install the callback instance referenced by argument listener into the UIViewRoot as a listener for events of type systemEventClass.

Parameters:
type - The system event type to listen on.
callback - The callback to be invoked.
Since:
1.2