001    package edu.nrao.sss.webapp.faces;
002    
003    import javax.faces.component.UIComponent;
004    import javax.faces.event.PhaseId;
005    import javax.faces.event.ValueChangeEvent;
006    import javax.faces.event.ActionEvent;
007    
008    /**
009     * Provides some static methods to help with JSF event queues
010     */
011    public class EventUtils
012    {
013      /**
014       * requeues the event {@code e} for execution in the phase {@pid}.  If pid is
015       * equal to the phase id of e, nothing is done.  If either argument is null,
016       * nothing is done.  Otherwise, a <em>copy</em> of {@code e} is queued for
017       * execution during phase {@code pid}.
018       */
019      public static void requeueEvent(ValueChangeEvent e, PhaseId pid)
020      {
021        if (e != null && pid != null && !pid.equals(e.getPhaseId()))
022        {
023          UIComponent c = e.getComponent();
024          ValueChangeEvent newEvent = new ValueChangeEvent(
025            c,
026            e.getOldValue(),
027            e.getNewValue()
028          );
029    
030          c.queueEvent(newEvent);
031          newEvent.setPhaseId(pid);
032        }
033      }
034    
035      /**
036       * requeues the event {@code e} for execution in the phase {@pid}.  If pid is
037       * equal to the phase id of e, nothing is done.  If either argument is null,
038       * nothing is done.  Otherwise, a <em>copy</em> of {@code e} is queued for
039       * execution during phase {@code pid}.
040       */
041      public static void requeueEvent(ActionEvent e, PhaseId pid)
042      {
043        if (e != null && pid != null && !pid.equals(e.getPhaseId()))
044        {
045          UIComponent c = e.getComponent();
046          ActionEvent newEvent = new ActionEvent(c);
047          c.queueEvent(newEvent);
048          newEvent.setPhaseId(pid);
049        }
050      }
051    }