源码讲解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. }  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值