private void checkEventQueueing(PhaseId phaseId) {

    // NOTE:  Current semantics for ANY_PHASE listeners is that
    // the event should be delivered exactly once, so the existence
    // of such a listener does not cause the event to remain queued.
    // Therefore, the expected string is the same as for any
    // phase-specific listener, and it should get matched after
    // Apply Request Values processing since that is first phase
    // for which events are fired

    // Register an event listener for the specified phase id
    UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null);
    facesContext.setViewRoot(root);
    TestEvent event = null;
    TestListener listener = new TestListener("t");
    root.addFacesListener(listener);

    // Queue some events to be processed
    event = new TestEvent(root, "1");
    event.setPhaseId(phaseId);
    root.queueEvent(event);
    event = new TestEvent(root, "2");
    event.setPhaseId(phaseId);
    root.queueEvent(event);
    String expected = "/t/1/t/2";

    // Fire off the relevant lifecycle methods and check expected results
    TestListener.trace(null);
    assertEquals("", TestListener.trace());
    root.processDecodes(facesContext);
    if (PhaseId.APPLY_REQUEST_VALUES.equals(phaseId) || PhaseId.ANY_PHASE.equals(phaseId)) {
      assertEquals(expected, TestListener.trace());
    } else {
      assertEquals("", TestListener.trace());
    }
    root.processValidators(facesContext);
    if (PhaseId.PROCESS_VALIDATIONS.equals(phaseId)
        || PhaseId.APPLY_REQUEST_VALUES.equals(phaseId)
        || PhaseId.APPLY_REQUEST_VALUES.equals(phaseId)
        || PhaseId.ANY_PHASE.equals(phaseId)) {
      assertEquals(expected, TestListener.trace());
    } else {
      assertEquals("", TestListener.trace());
    }
    root.processUpdates(facesContext);
    if (PhaseId.UPDATE_MODEL_VALUES.equals(phaseId)
        || PhaseId.PROCESS_VALIDATIONS.equals(phaseId)
        || PhaseId.APPLY_REQUEST_VALUES.equals(phaseId)
        || PhaseId.ANY_PHASE.equals(phaseId)) {
      assertEquals(expected, TestListener.trace());
    } else {
      assertEquals("", TestListener.trace());
    }
    root.processApplication(facesContext);
    assertEquals(expected, TestListener.trace());
  }
Beispiel #2
0
 /**
  * Informs phase listeners after a phase is executed
  *
  * @param facesContext The current faces context
  * @param phaseId The phase id that was executed
  */
 protected void informPhaseListenersAfter(FacesContext facesContext, PhaseId phaseId) {
   Lifecycle lifecycle = getLifecycle();
   PhaseListener[] phaseListeners = lifecycle.getPhaseListeners();
   for (int i = 0; i < phaseListeners.length; i++) {
     PhaseListener phaseListener = phaseListeners[i];
     int listenerPhaseId = phaseListener.getPhaseId().getOrdinal();
     if (listenerPhaseId == PhaseId.ANY_PHASE.getOrdinal()
         || listenerPhaseId == phaseId.getOrdinal()) {
       phaseListener.afterPhase(
           new PhaseEvent(FacesContext.getCurrentInstance(), phaseId, lifecycle));
     }
   }
 }
 /**
  * @param phaseListener
  * @param phaseEvent
  * @param beforePhase
  */
 private void invokePhaseListener(
     PhaseListener phaseListener, PhaseEvent phaseEvent, boolean beforePhase) {
   if (phaseEvent.getPhaseId().equals(phaseListener.getPhaseId())
       || PhaseId.ANY_PHASE.equals(phaseListener.getPhaseId())) {
     try {
       if (beforePhase) {
         phaseListener.beforePhase(phaseEvent);
       } else {
         phaseListener.afterPhase(phaseEvent);
       }
     } catch (Exception e) {
       _log.debug(
           "Exception in PhaseListener, phase :"
               + phaseEvent.getPhaseId().toString()
               + (beforePhase ? " : beforePhase" : " : afterPhase"),
           e);
     }
   }
 }
Beispiel #4
0
 protected boolean isTargetListener(PhaseListener listener, PhaseId phaseId) {
   int listenerOrdinal = listener.getPhaseId().getOrdinal();
   return listenerOrdinal == PhaseId.ANY_PHASE.getOrdinal()
       || listenerOrdinal == phaseId.getOrdinal();
 }