/** Restores the messages from the cache before the Restore View phase. */
 @Override
 public synchronized void beforePhase(PhaseEvent event) {
   LOGGER.trace(event.getPhaseId().toString() + " - Before Phase");
   if (event.getPhaseId() == PhaseId.RESTORE_VIEW) {
     restoreMessages(event.getFacesContext());
   }
 }
Exemple #2
0
  /**
   * Perform actions that need to happen on the <code>afterPhase</code> event.
   *
   * <p>For after restore-view, if this is a postback, we extract the sequenceId from the request
   * and store it in the request scope.
   *
   * <p>For after render-response, we clear out the flash for the postback, while leaving the
   * current one intact.
   */
  public void afterPhase(PhaseEvent e) {
    FacesContext context = e.getFacesContext();
    ExternalContext extContext = context.getExternalContext();
    Map<String, Object> requestMap = extContext.getRequestMap();
    Object request = extContext.getRequest(), response = extContext.getResponse();
    ELFlash elFlash = ELFlash.getELFlash();

    if (e.getPhaseId().equals(PhaseId.RENDER_RESPONSE)) {
      expireEntries(context);
    }

    // If this requset is ending normally...
    if (e.getPhaseId().equals(PhaseId.RENDER_RESPONSE)) {
      // and the user requested we save all request scoped data...
      if (null != elFlash && elFlash.isKeepMessages()) {
        // save it all.
        elFlash.saveAllMessages(context);
      }
    }
    // Otherwise, if this request is ending early...
    else if ((context.getResponseComplete() || context.getRenderResponse())
        && elFlash.isRedirect()) {
      // and the user requested we save all request scoped data...
      if (null != elFlash && elFlash.isKeepMessages()) {
        // save it all.
        addCookie(extContext, elFlash);
        elFlash.saveAllMessages(context);
      }
    }
  }
 public void afterPhase(PhaseEvent event) {
   phaseCalled[event.getPhaseId().getOrdinal()] =
       phaseCalled[event.getPhaseId().getOrdinal()] + 1;
   if (throwExceptionOnAfter) {
     throw new IllegalStateException(
         "throwing exception on after " + event.getPhaseId().toString());
   }
 }
 /**
  * Caches Faces Messages after the Invoke Application phase and clears the cache after the Render
  * Response phase.
  */
 @Override
 public synchronized void afterPhase(PhaseEvent event) {
   LOGGER.trace(event.getPhaseId().toString() + " - After Phase");
   if (event.getPhaseId() == PhaseId.INVOKE_APPLICATION) {
     cacheMessages(event.getFacesContext());
   } else if (event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
     removeFromCache(event.getFacesContext());
   }
 }
 // Antes da Fase
 @Override
 public void beforePhase(PhaseEvent fase) {
   System.out.println("Antes da fase: " + fase.getPhaseId());
   if (fase.getPhaseId().equals(PhaseId.RESTORE_VIEW)) {
     Session session = HibernateUtil.getSessionFactory().openSession();
     session.beginTransaction();
     FacesContextUtil.setRequestSession(session);
   }
 }
 public void beforePhase(PhaseEvent event) {
   phaseCalled[event.getPhaseId().getOrdinal()] =
       phaseCalled[event.getPhaseId().getOrdinal()] + 1;
   if (callRenderResponseBeforeThisPhase == event.getPhaseId()) {
     FacesContext.getCurrentInstance().renderResponse();
   }
   if (throwExceptionOnBefore) {
     throw new IllegalStateException(
         "throwing exception on before " + event.getPhaseId().toString());
   }
 }
 /** @see javax.faces.event.PhaseListener#beforePhase(javax.faces.event.PhaseEvent) */
 public void beforePhase(PhaseEvent event) {
   LOGGER.debug("Before phase {0}", event.getPhaseId());
   if (event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
     UIViewRoot viewRoot = event.getFacesContext().getViewRoot();
     if (viewRoot != null) {
       LOGGER.debug(
           "Subscribing to event {0} with listener {1}", PRERENDER_EVENT_CLASS, HOOKING_EVENT);
       viewRoot.subscribeToEvent(PRERENDER_EVENT_CLASS, HOOKING_EVENT);
     }
   }
 }
Exemple #8
0
  /**
   * Perform actions that need to happen on the <code>beforePhase</code> event.
   *
   * <p>For all phases, store the current phaseId in request scope.
   *
   * <p>For before restore-view, create a sequenceId for this request and store it in request scope.
   *
   * <p>For before render-response, store the sequenceId for this request in the response.
   */
  public void beforePhase(PhaseEvent e) {
    FacesContext context = e.getFacesContext();
    ExternalContext extContext = context.getExternalContext();
    Object response = extContext.getResponse();
    Map<String, Object> requestMap = extContext.getRequestMap();
    String thisRequestSequenceString = null;
    String postbackSequenceString = null;
    ELFlash elFlash = (ELFlash) ELFlash.getFlash(context, true);

    // If we're on before-restore-view...
    if (e.getPhaseId().equals(PhaseId.RESTORE_VIEW)) {
      thisRequestSequenceString = Long.toString(getSequenceNumber());
      // Put the sequence number for the request/response pair
      // that is starting with *this particular request* in the request scope
      // so the ELFlash can access it.
      requestMap.put(Constants.FLASH_THIS_REQUEST_ATTRIBUTE_NAME, thisRequestSequenceString);

      // Make sure to restore all request scoped data
      if (null != elFlash && elFlash.isKeepMessages()) {
        elFlash.restoreAllMessages(context);
      }

      if (context.isPostback()) {
        // to a servlet JSF app...
        if (response instanceof HttpServletResponse) {
          // extract the sequence number from the cookie or portletSession
          // for the request/response pair for which this request is a postback.
          postbackSequenceString = getCookieValue(extContext);
        } else {
          /**
           * **** PortletRequest portletRequest = null; portletRequest = (PortletRequest) request;
           * // You can't retrieve a cookie in portlet. //
           * http://wiki.java.net/bin/view/Portlet/JSR168FAQ#How_can_I_set_retrieve_a_cookie
           * postbackSequenceString = (String) portletRequest.getPortletSession().
           * getAttribute(Constants.FLASH_POSTBACK_REQUEST_ATTRIBUTE_NAME,
           * PortletSession.PORTLET_SCOPE); *****
           */
        }
        if (null != postbackSequenceString) {
          // Store the sequenceNumber in the request so the
          // after-render-response event can flush the flash
          // of entries from that sequence
          requestMap.put(Constants.FLASH_POSTBACK_REQUEST_ATTRIBUTE_NAME, postbackSequenceString);
        }
      }
    }
    if (e.getPhaseId().equals(PhaseId.RENDER_RESPONSE)) {
      // Set the REQUEST_ID cookie to be the sequence number
      addCookie(extContext, elFlash);
    }
  }
 /** @see javax.faces.event.PhaseListener#afterPhase(javax.faces.event.PhaseEvent) */
 public void afterPhase(PhaseEvent event) {
   LOGGER.debug("After phase {0}", event.getPhaseId());
   if (event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
     UIViewRoot viewRoot = event.getFacesContext().getViewRoot();
     if (viewRoot != null) {
       ServiceRegisterJSComponent serviceRegister =
           InternalEventListener.findServiceRegister(FacesContext.getCurrentInstance());
       if (serviceRegister != null) {
         LOGGER.debug("Found service register with clientId {0}", serviceRegister.getClientId());
       } else {
         LOGGER.debug("Service register not found!");
       }
     }
   }
 }
  public void beforePhase(PhaseEvent phaseEvent) {

    Bridge.PortletPhase portletRequestPhase = BridgeUtil.getPortletRequestPhase();

    if ((portletRequestPhase == Bridge.PortletPhase.RENDER_PHASE)
        || (portletRequestPhase == Bridge.PortletPhase.RESOURCE_PHASE)) {

      // If about to execute the INVOKE_APPLICATION phase of the JSF lifecycle, then
      if (phaseEvent.getPhaseId() == PhaseId.INVOKE_APPLICATION) {
        beforeInvokeApplicationPhase(phaseEvent);
      } else if (phaseEvent.getPhaseId() == PhaseId.RENDER_RESPONSE) {
        beforeRenderResponsePhase(phaseEvent);
      }
    }
  }
 // Depois da Fase
 @Override
 public void afterPhase(PhaseEvent fase) {
   System.out.println("Depois da fase: " + fase.getPhaseId());
   if (fase.getPhaseId().equals(PhaseId.RENDER_RESPONSE)) {
     Session session = FacesContextUtil.getRequestSession();
     try {
       session.getTransaction().commit();
     } catch (Exception e) {
       if (session.getTransaction().isActive()) {
         session.getTransaction().rollback();
       }
     } finally {
       session.close();
     }
   }
 }
 @Override
 public void afterPhase(PhaseEvent phaseEvent) {
   PhaseId currPhaseId = phaseEvent.getPhaseId();
   if (currPhaseId.equals(PhaseId.RESTORE_VIEW)) {
     verify(phaseEvent);
   }
 }
 @Override
 public void beforePhase(PhaseEvent phaseEvent) {
   PhaseId currPhaseId = phaseEvent.getPhaseId();
   if (currPhaseId.equals(PhaseId.RENDER_RESPONSE)) {
     verify(phaseEvent);
   }
 }
 @Override
 public void beforePhase(PhaseEvent arg0) {
   // TODO Auto-generated method stub
   System.out.println("Before Phase:" + arg0.getSource());
   System.out.println("Before Phase:" + arg0.getFacesContext());
   System.out.println("Before Phase:" + arg0.getClass());
   System.out.println("Before Phase:" + arg0.getPhaseId());
 }
 /**
  * @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);
     }
   }
 }
  // TODO: Blog this (MultiPageMessagesSupport)
  public void beforePhase(final PhaseEvent event) {
    FacesContext facesContext = event.getFacesContext();
    this.saveMessages(facesContext);

    if (PhaseId.RENDER_RESPONSE.equals(event.getPhaseId())) {
      if (!facesContext.getResponseComplete()) {
        this.restoreMessages(facesContext);
      }
    }
  }
  public void beforePhase(PhaseEvent phaseEvent) {

    Bridge.PortletPhase portletRequestPhase =
        BridgeUtil.getPortletRequestPhase(phaseEvent.getFacesContext());

    if ((portletRequestPhase == Bridge.PortletPhase.RESOURCE_PHASE)
        || (portletRequestPhase == Bridge.PortletPhase.RENDER_PHASE)) {

      if (phaseEvent.getPhaseId() == PhaseId.APPLY_REQUEST_VALUES) {
        beforeApplyRequestValuesPhase(phaseEvent);
      } else if (phaseEvent.getPhaseId() == PhaseId.RENDER_RESPONSE) {
        FacesContext facesContext = phaseEvent.getFacesContext();

        if (facesContext.getPartialViewContext().isAjaxRequest()) {
          beforeAjaxifiedRenderResponsePhase(phaseEvent);
        }
      }
    }
  }
  public void afterPhase(PhaseEvent phaseEvent) {

    // This method just does some logging. It's useful to the developer to determine if a
    // navigation-rule
    // fired, causing new JSF view to be restored after the INVOKE_APPLICATION phase finished.
    if (logger.isDebugEnabled() && (phaseEvent.getPhaseId() == PhaseId.INVOKE_APPLICATION)) {
      FacesContext facesContext = phaseEvent.getFacesContext();
      String viewId = facesContext.getViewRoot().getViewId();
      logger.debug("After INVOKE_APPLICATION: viewId=[{0}]", viewId);
    }
  }
 private void endSession(PhaseEvent event) {
   if (event.getPhaseId().equals(PhaseId.RENDER_RESPONSE)) {
     final SessionHolder sessionHolder =
         (SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory);
     if (sessionHolder != null
         && !FlushMode.MANUAL.equals(sessionHolder.getSession().getFlushMode())) {
       sessionHolder.getSession().flush();
     }
     if (boundByMe.get()) unbindSession();
   }
 }
Exemple #20
0
  public void afterPhase(PhaseEvent event) {
    Long phaseStartTime = phaseTimer.get();

    long measuredTime = 0;
    if (phaseStartTime != null) {
      measuredTime = System.currentTimeMillis() - phaseStartTime.longValue();
    }

    logger.debug(
        MessageFormat.format("Phase {0} completed by {1}ms", event.getPhaseId(), measuredTime));
    phaseTimer.set(null);
  }
  public void afterPhase(PhaseEvent event) {
    if (checkPortletMultipleNotifications(event, false)) return;

    FacesContext context = event.getFacesContext();
    PhaseId phaseId = event.getPhaseId();
    if (phaseId.equals(PhaseId.RENDER_RESPONSE)) {
      //            appendHeaderContent(context);
    } else if (phaseId.equals(PhaseId.APPLY_REQUEST_VALUES)) {
      decodeFocusTracking(context);
      decodeScrollPosTracking(context);
    }
  }
  private static void onEvent(PhaseEvent event, String prefix) {
    PhaseId phase = event.getPhaseId();
    Object source = event.getSource();

    DebugMessage message = new DebugMessage();
    message.event = prefix + " " + phase;
    message.source = getObjectString(source);
    message.component = null;
    message.details = null;
    message.type = TYPE_LIFECYCLE;

    messages.add(message);
  }
 public void afterPhase(PhaseEvent event) {
   if (PhaseId.RESTORE_VIEW.equals(event.getPhaseId())) {
     if ("/conversations.xhtml".equals(getViewId(event))) {
       try {
         HttpServletRequest request =
             (HttpServletRequest) event.getFacesContext().getExternalContext().getRequest();
         HttpServletResponse response =
             (HttpServletResponse) event.getFacesContext().getExternalContext().getResponse();
         request.getRequestDispatcher("/result.jsf").forward(request, response);
         event.getFacesContext().responseComplete();
       } catch (Exception e) {
         throw new RuntimeException("blah", e);
       }
     }
   }
 }
 public void beforePhase(PhaseEvent event) {
   if (PhaseId.RESTORE_VIEW.equals(event.getPhaseId())) {
     String uri =
         ((HttpServletRequest) event.getFacesContext().getExternalContext().getRequest())
             .getRequestURI();
     if (uri.contains("missing-page-error")) {
       try {
         HttpServletResponse response =
             (HttpServletResponse) event.getFacesContext().getExternalContext().getResponse();
         response.sendError(404);
         event.getFacesContext().responseComplete();
       } catch (Exception e) {
         throw new RuntimeException("blah", e);
       }
     }
   }
 }
 @Override
 public void afterPhase(PhaseEvent phase) {
   System.out.println("Depois da fase: " + phase.getPhaseId());
 }
 /*
  * Save messages into the session after every phase.
  */
 public void afterPhase(final PhaseEvent event) {
   if (!PhaseId.RENDER_RESPONSE.equals(event.getPhaseId())) {
     FacesContext facesContext = event.getFacesContext();
     this.saveMessages(facesContext);
   }
 }
Exemple #27
0
 public void beforePhase(PhaseEvent event) {
   event.getFacesContext().getExternalContext().log("BEFORE " + event.getPhaseId());
 }
Exemple #28
0
 public void modify(PhaseEvent e) {
   if (!e.getPhaseId().equals(PhaseId.APPLY_REQUEST_VALUES)) {
     return;
   }
   append();
 }
Exemple #29
0
 public void afterPhase(PhaseEvent event) {
   event.getFacesContext().getExternalContext().log("AFTER " + event.getPhaseId());
 }
 @Override
 public void beforePhase(PhaseEvent phase) {
   System.out.println("Antes da fase: " + phase.getPhaseId());
 }