源码讲解renderResponse和responseComplete的区别

看源代码:
responseComplete:
  1. /**  
  2.     * <p>Signal the JavaServer Faces implementation that the HTTP response  
  3.     * for this request has already been generated (such as an HTTP redirect),  
  4.     * and that the request processing lifecycle should be terminated as soon  
  5.     * as the current phase is completed.</p>  
  6.     *  
  7.     * @throws IllegalStateException if this method is called after  
  8.     *  this instance has been released  
  9.     */  
  10.    public abstract void responseComplete();  
renderResponse:
  1. /**  
  2.   * <p>Signal the JavaServer faces implementation that, as soon as the  
  3.   * current phase of the request processing lifecycle has been completed,  
  4.   * control should be passed to the <em>Render Response</em> phase,  
  5.   * bypassing any phases that have not been executed yet.</p>  
  6.   *  
  7.   * @throws IllegalStateException if this method is called after  
  8.   *  this instance has been released  
  9.   */  
  10.  public abstract void renderResponse();  

responseComplete和renderResponse的关系有点象break和continue的关系,responseComplete指示当前的response已经产生,JSF应该在当前阶段执行完成后立刻整个生命周期,break的概念。renderResponse则是指示当前阶段执行结束后直接跳到Render Response阶段,继续生命周期,因此是continue的概念。

下面是LifeCycle的execute和render方法,更加证实了这些:

com.sun.faces.lifecycle.LifecycleImpl
  1. // Execute the phases up to but not including Render Response   
  2. public void execute(FacesContext context) throws FacesException {   
  3.   
  4.     if (context == null) {   
  5.         throw new NullPointerException   
  6.             (MessageUtils.getExceptionMessageString   
  7.              (MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "context"));   
  8.     }   
  9.   
  10.     if (LOGGER.isLoggable(Level.FINE)) {   
  11.         LOGGER.fine("execute(" + context + ")");   
  12.     }   
  13.   
  14.     for (int i = 1, len = phases.length -1 ; i < len; i++) { // Skip ANY_PHASE placeholder   
  15.   
  16.         if (context.getRenderResponse() ||   
  17.             context.getResponseComplete()) {   
  18.             break;   
  19.         }   
  20.   
  21.         phases[i].doPhase(context, this, listeners.listIterator());   
  22.   
  23.     }   
  24.   
  25. }   
  26.   
  27.   
  28. // Execute the Render Response phase   
  29. public void render(FacesContext context) throws FacesException {   
  30.   
  31.     if (context == null) {   
  32.         throw new NullPointerException   
  33.             (MessageUtils.getExceptionMessageString   
  34.              (MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "context"));   
  35.     }   
  36.   
  37.     if (LOGGER.isLoggable(Level.FINE)) {   
  38.         LOGGER.fine("render(" + context + ")");   
  39.     }   
  40.   
  41.     if (!context.getResponseComplete()) {   
  42.         response.doPhase(context, this, listeners.listIterator());   
  43.     }   
  44.   
  45. }  

你可能感兴趣的:(JSF,UP,sun)