renderResponse和responseComplete

源码讲解renderResponse和responseComplete的区别
关键字: renderResponse responseComplete
看源代码:
responseComplete:
/**
* <p>Signal the JavaServer Faces implementation that the HTTP response
* for this request has already been generated (such as an HTTP redirect),
* and that the request processing lifecycle should be terminated as soon
* as the current phase is completed.</p>
*
* @throws IllegalStateException if this method is called after
* this instance has been released
*/
public abstract void responseComplete();

renderResponse:
/**
* <p>Signal the JavaServer faces implementation that, as soon as the
* current phase of the request processing lifecycle has been completed,
* control should be passed to the <em>Render Response</em> phase,
* bypassing any phases that have not been executed yet.</p>
*
* @throws IllegalStateException if this method is called after
* this instance has been released
*/
public abstract void renderResponse();

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

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

com.sun.faces.lifecycle.LifecycleImpl
// Execute the phases up to but not including Render Response
public void execute(FacesContext context) throws FacesException {

if (context == null) {
throw new NullPointerException
(MessageUtils.getExceptionMessageString
(MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "context"));
}

if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("execute(" + context + ")");
}

for (int i = 1, len = phases.length -1 ; i < len; i++) { // Skip ANY_PHASE placeholder

if (context.getRenderResponse() ||
context.getResponseComplete()) {
break;
}

phases[i].doPhase(context, this, listeners.listIterator());

}

}


// Execute the Render Response phase
public void render(FacesContext context) throws FacesException {

if (context == null) {
throw new NullPointerException
(MessageUtils.getExceptionMessageString
(MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "context"));
}

if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("render(" + context + ")");
}

if (!context.getResponseComplete()) {
response.doPhase(context, this, listeners.listIterator());
}

}
一般加ResponseComplete之后,当前页面会变成空白,这对于后台关闭页面可用
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值