コード例 #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());
  }
コード例 #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);
   }
 }
コード例 #3
0
  // Test Events List Clearing
  public void testEventsListClear() {
    UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null);
    facesContext.setViewRoot(root);
    TestEvent event1, event2, event3, event4 = null;
    event1 = new TestEvent(root, "1");
    event1.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
    root.queueEvent(event1);
    event2 = new TestEvent(root, "2");
    event2.setPhaseId(PhaseId.PROCESS_VALIDATIONS);
    root.queueEvent(event2);
    event3 = new TestEvent(root, "3");
    event3.setPhaseId(PhaseId.UPDATE_MODEL_VALUES);
    root.queueEvent(event3);
    event4 = new TestEvent(root, "4");
    event4.setPhaseId(PhaseId.INVOKE_APPLICATION);
    root.queueEvent(event4);
    final Field fields[] = UIViewRoot.class.getDeclaredFields();
    Field field = null;
    List<List> events = null;
    for (int i = 0; i < fields.length; ++i) {
      if ("events".equals(fields[i].getName())) {
        field = fields[i];
        field.setAccessible(true);
        try {
          events = TypedCollections.dynamicallyCastList((List) field.get(root), List.class);
        } catch (Exception e) {
          assertTrue(false);
        }
        break;
      }
    }
    // CASE: renderReponse not set; responseComplete not set;
    // check for existence of events before processDecodes
    checkEventQueuesSizes(events, 1, 1, 1, 1);
    root.processDecodes(facesContext);
    // there should be no events
    checkEventQueuesSizes(events, 0, 1, 1, 1);

    // requeue apply request event
    root.queueEvent(event1);
    // CASE: renderReponse set;
    // check for existence of events before processValidators
    checkEventQueuesSizes(events, 1, 1, 1, 1);
    facesContext.renderResponse();
    root.processValidators(facesContext);
    // there should be no events
    checkEventQueuesSizes(events, 0, 0, 0, 0);

    // reset FacesContext
    facesContext.setRenderResponse(false);
    facesContext.setResponseComplete(false);
    // requeue all events
    root.queueEvent(event1);
    root.queueEvent(event2);
    root.queueEvent(event3);
    root.queueEvent(event4);
    try {
      events = TypedCollections.dynamicallyCastList((List) field.get(root), List.class);
    } catch (Exception e) {
      assertTrue(false);
    }
    // CASE: response set;
    // check for existence of events before processValidators
    checkEventQueuesSizes(events, 1, 1, 1, 1);
    facesContext.renderResponse();
    root.processValidators(facesContext);
    // there should be no events
    checkEventQueuesSizes(events, 0, 0, 0, 0);

    // reset FacesContext
    facesContext.setRenderResponse(false);
    facesContext.setResponseComplete(false);
    // requeue all events
    root.queueEvent(event1);
    root.queueEvent(event2);
    root.queueEvent(event3);
    root.queueEvent(event4);
    try {
      events = TypedCollections.dynamicallyCastList((List) field.get(root), List.class);
    } catch (Exception e) {
      assertTrue(false);
    }
    // CASE: response complete;
    // check for existence of events before processUpdates
    checkEventQueuesSizes(events, 1, 1, 1, 1);
    facesContext.responseComplete();
    root.processUpdates(facesContext);
    // there should be no events
    checkEventQueuesSizes(events, 0, 0, 0, 0);

    // reset FacesContext
    facesContext.setRenderResponse(false);
    facesContext.setResponseComplete(false);
    // requeue all events
    root.queueEvent(event1);
    root.queueEvent(event2);
    root.queueEvent(event3);
    root.queueEvent(event4);
    try {
      events = TypedCollections.dynamicallyCastList((List) field.get(root), List.class);
    } catch (Exception e) {
      assertTrue(false);
    }
    // CASE: response complete;
    // check for existence of events before processApplication
    checkEventQueuesSizes(events, 1, 1, 1, 1);
    facesContext.responseComplete();
    root.processApplication(facesContext);
    // there should be no events
    checkEventQueuesSizes(events, 0, 0, 0, 0);

    // finally, get the internal events list one more time
    // to make sure it is null
    try {
      events = TypedCollections.dynamicallyCastList((List) field.get(root), List.class);
    } catch (Exception e) {
      assertTrue(false);
    }
    assertNull("events", events);
  }
コード例 #4
0
ファイル: LifecycleImpl.java プロジェクト: dlitz/resin
  public void execute(FacesContext context) throws FacesException {
    boolean isFiner = log.isLoggable(Level.FINER);

    if (context.getResponseComplete() || context.getRenderResponse()) return;

    beforePhase(context, PhaseId.RESTORE_VIEW);

    try {
      if (isFiner) log.finer("JSF[] before restore view");

      restoreView(context);
    } finally {
      afterPhase(context, PhaseId.RESTORE_VIEW);
    }

    if (context.getResponseComplete() || context.getRenderResponse()) return;

    UIViewRoot viewRoot = context.getViewRoot();

    beforePhase(context, PhaseId.APPLY_REQUEST_VALUES);

    try {
      if (isFiner) log.finer(context.getViewRoot() + " before process decodes");

      viewRoot.processDecodes(context);
    } catch (RuntimeException e) {
      log.log(Level.WARNING, e.toString(), e);
    } finally {
      afterPhase(context, PhaseId.APPLY_REQUEST_VALUES);
    }

    //
    // Process Validations (processValidators)
    //

    if (context.getResponseComplete() || context.getRenderResponse()) return;

    beforePhase(context, PhaseId.PROCESS_VALIDATIONS);

    try {
      if (isFiner) log.finer(context.getViewRoot() + " before process validators");

      viewRoot.processValidators(context);
    } finally {
      afterPhase(context, PhaseId.PROCESS_VALIDATIONS);
    }

    //
    // Update Model Values (processUpdates)
    //

    if (context.getResponseComplete() || context.getRenderResponse()) return;

    beforePhase(context, PhaseId.UPDATE_MODEL_VALUES);

    try {
      if (isFiner) log.finer(context.getViewRoot() + " before process updates");

      viewRoot.processUpdates(context);
    } catch (RuntimeException e) {
      if (sendError(context, "processUpdates", e)) return;
    } finally {
      afterPhase(context, PhaseId.UPDATE_MODEL_VALUES);
    }

    //
    // Invoke Application (processApplication)
    //

    if (context.getResponseComplete() || context.getRenderResponse()) return;

    beforePhase(context, PhaseId.INVOKE_APPLICATION);

    try {
      if (isFiner) log.finer(context.getViewRoot() + " before process application");

      viewRoot.processApplication(context);
    } finally {
      afterPhase(context, PhaseId.INVOKE_APPLICATION);
    }
  }