Пример #1
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 context
   * @param resource
   * @throws IOException
   */
  public void send(ResourceContext resourceContext, InternetResource resource) throws IOException {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    if (null != facesContext) {
      Lifecycle facesLifecycle = getFacesLifecycle();
      PhaseListener[] phaseListeners = facesLifecycle.getPhaseListeners();
      PhaseEvent restoreViewEvent = new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW, this);
      processPhaseListeners(phaseListeners, restoreViewEvent, true);
      // Fix for a http://jira.jboss.org/jira/browse/RF-1056
      if (facesContext.getResponseComplete()) {
        return;
      }
      // fix for a http://jira.jboss.com/jira/browse/RF-1064 .
      // viewRoot can be created outside.
      UIViewRoot savedViewRoot = facesContext.getViewRoot();
      try {
        // create "dummy" viewRoot, to avoid problems in phase listeners.
        UIViewRoot root = new UIViewRoot();
        String key = resource.getKey();
        if (null != key && !key.startsWith("/")) {
          key = "/" + key;
        }
        root.setViewId(key);
        root.setLocale(Locale.getDefault());
        root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
        facesContext.setViewRoot(root);
        // We do not simulate other phases.
        facesContext.renderResponse();
        // Invoke after restore view phase listeners
        processPhaseListeners(phaseListeners, restoreViewEvent, false);
        // Fix for a http://jira.jboss.org/jira/browse/RF-1056
        if (!facesContext.getResponseComplete()) {
          // Invoke before render view phase listeners
          PhaseEvent renderViewEvent = new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE, this);

          try {
            processPhaseListeners(phaseListeners, renderViewEvent, true);
            sendResource(resourceContext, resource);
          } finally {
            processPhaseListeners(phaseListeners, renderViewEvent, false);
          }
        }

      } finally {
        if (null != savedViewRoot) {
          facesContext.setViewRoot(savedViewRoot);
        }
      }
    } else {
      sendResource(resourceContext, resource);
    }
  }
Пример #3
0
 public final void postPhase(FacesContext context) {
   Lifecycle lifecycle = getLifecycle();
   PhaseListener[] phaseListeners = lifecycle.getPhaseListeners();
   if (phaseListeners != null) {
     for (int i = phaseListeners.length - 1; i >= 0; i--) {
       PhaseListener phaseListener = phaseListeners[i];
       PhaseId phaseId = getCurrentPhaseId();
       if (isTargetListener(phaseListener, phaseId)) {
         PhaseEvent event = createPhaseEvent(context, phaseId, lifecycle);
         phaseListener.afterPhase(event);
       }
     }
   }
 }
Пример #4
0
  protected void processOutgoingPublicRenderParameters(Lifecycle lifecycle) {

    PhaseListener[] phaseListeners = lifecycle.getPhaseListeners();

    for (PhaseListener phaseListener : phaseListeners) {

      if (phaseListener instanceof IPCPhaseListener) {
        IPCPhaseListener ipcPhaseListener = (IPCPhaseListener) phaseListener;
        ipcPhaseListener.processOutgoingPublicRenderParameters(bridgeContext, facesContext);

        break;
      }
    }
  }
 /**
  * ICE-1084 : We have to turn off Seam's PhaseListener that makes it's debug page appear, so that
  * our SeamDebugResourceResolver can do its work.
  *
  * @param lifecycle The Lifecycle maintains the list of PhaseListeners
  */
 public static void removeSeamDebugPhaseListener(Lifecycle lifecycle) {
   PhaseListener[] phaseListeners = lifecycle.getPhaseListeners();
   //  System.out.println("*** SeamUtilities.removeSeamDebugPhaseListener()");
   // System.out.println("***   phaseListeners: " + phaseListeners.length);
   for (int i = 0; i < phaseListeners.length; i++) {
     // System.out.println("***     phaseListeners["+i+"]: " + phaseListeners[i]);
     if (phaseListeners[i]
         .getClass()
         .getName()
         .equals("org.jboss.seam.debug.jsf.SeamDebugPhaseListener")) {
       lifecycle.removePhaseListener(phaseListeners[i]);
       // System.out.println("***       REMOVED: " + phaseListeners[i]);
       seamDebugPhaseListenerClassLoader = phaseListeners[i].getClass().getClassLoader();
       // System.out.println("******      SeamDebugPhaseListener.class.getClassLoader(): " +
       // phaseListeners[i].getClass().getClassLoader());
     }
   }
 }
Пример #6
0
  public boolean isOrderCorrect() {

    LifecycleFactory factory =
        (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
    Lifecycle l = factory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
    PhaseListener[] listeners = l.getPhaseListeners();
    List<PhaseListener> list = new ArrayList<PhaseListener>();
    for (PhaseListener listener : listeners) {
      if (listener.getClass().getName().contains("com.sun.faces.systest.model.PhaseListener")) {
        list.add(listener);
      }
    }
    listeners = list.toArray(new PhaseListener[list.size()]);
    String[] suffixes = {"C", "B", "A", "D"};
    for (int i = 0; i < listeners.length; i++) {
      if (!listeners[i].getClass().getName().endsWith(suffixes[i])) {
        System.out.println("INCORRECT DOCUMENT ORDERING: " + Arrays.toString(listeners));
        return false;
      }
    }

    return true;
  }