Ejemplo n.º 1
0
  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());
  }
Ejemplo n.º 2
0
 private void callRightLifecycleMethodGivenPhaseId(UIViewRoot root, PhaseId phaseId)
     throws Exception {
   if (phaseId.getOrdinal() == PhaseId.APPLY_REQUEST_VALUES.getOrdinal()) {
     root.processDecodes(facesContext);
   } else if (phaseId.getOrdinal() == PhaseId.PROCESS_VALIDATIONS.getOrdinal()) {
     root.processValidators(facesContext);
   } else if (phaseId.getOrdinal() == PhaseId.UPDATE_MODEL_VALUES.getOrdinal()) {
     root.processUpdates(facesContext);
   } else if (phaseId.getOrdinal() == PhaseId.INVOKE_APPLICATION.getOrdinal()) {
     root.processApplication(facesContext);
   } else if (phaseId.getOrdinal() == PhaseId.RENDER_RESPONSE.getOrdinal()) {
     root.encodeBegin(facesContext);
     root.encodeEnd(facesContext);
   }
 }
Ejemplo n.º 3
0
 private void checkEventQueuesSizes(
     List<List> events,
     int applyEventsSize,
     int valEventsSize,
     int updateEventsSize,
     int appEventsSize) {
   List applyEvents = events.get(PhaseId.APPLY_REQUEST_VALUES.getOrdinal());
   assertEquals("Apply-Request-Values Event Count", applyEventsSize, applyEvents.size());
   List valEvents = events.get(PhaseId.PROCESS_VALIDATIONS.getOrdinal());
   assertEquals("Process-Validations Event Count", valEventsSize, valEvents.size());
   List updateEvents = events.get(PhaseId.UPDATE_MODEL_VALUES.getOrdinal());
   assertEquals("Update-Model Event Count", updateEventsSize, updateEvents.size());
   List appEvents = events.get(PhaseId.INVOKE_APPLICATION.getOrdinal());
   assertEquals("Invoke-Application Event Count", appEventsSize, appEvents.size());
 }
Ejemplo n.º 4
0
  /**
   * Process specified JSF life-cycle phase.
   *
   * @param context faces context.
   * @param phase current JSF life-cycle phase identifier.
   */
  private void process(FacesContext context, PhaseId phase) {
    if (!this.isRendered()) return;
    this.setIndex(null);

    if (this.getChildCount() > 0) {
      while (this.hasNext()) {
        this.next();
        if (PhaseId.APPLY_REQUEST_VALUES.equals(phase)) {
          super.processDecodes(context);
        } else if (PhaseId.PROCESS_VALIDATIONS.equals(phase)) {
          super.processValidators(context);
        } else if (PhaseId.UPDATE_MODEL_VALUES.equals(phase)) {
          super.processUpdates(context);
        }
      }
    }
    this.setIndex(null);
  }