`
anranran
  • 浏览: 29079 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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之后,当前页面会变成空白,这对于后台关闭页面可用
分享到:
评论

相关推荐

    j2ee期末考试题下载

    Faces请求生成非Faces响应使用FacesContext.responseComplete 方法来呈现响应阶段,而非Faces请求生成Faces响应使用FacesContext.renderResponse 方法来呈现响应阶段。 在JSP 中,sql 标签不符合分层原则,sql ...

    jsf例子\监听器 例子

    监听器可以影响生命周期的进程,例如通过调用`FacesContext.renderResponse()`提前结束当前阶段,或者调用`FacesContext.responseComplete()`立即终止整个生命周期。 4. **事件处理与JSF生命周期的关系**: 在JSF...

    JSF生命周期及组件开发P

    JSF的生命周期允许开发者灵活地插入自定义的行为,比如通过调用`FacesContext.responseComplete()`或`FacesContext.renderResponse()`来改变流程。理解生命周期对于有效地编写JSF应用程序至关重要,因为它指导了何时...

    Apache click 中文文档

    Click 还支持创建复杂的表格和表单,可以轻松地处理数据展示和用户输入。 **表格示例:** 可以使用 Click 的内置表格控件来展示数据。 **示例:** ```java public class TablePage extends Page { private Table...

    j2ee 考试题 j2ee两份考试题

    FacesContext.renderResponse,跳到 和 A. FacesContext.responseComplete,跳过。 #### 二、填空题解析 **1. Web组件类型** - **知识点解释**:Web组件包括 Java Servlet、JSP 页面和 Web 服务端点等。这些组件...

    JSR-168 Portlet指南.doc

    JSR-168,全称为Java Specification Request 168,是Java社区制定的一项标准,旨在为portlet开发者提供一套API,以实现portlet的可移植性和互操作性。Portlet是一种组件化的应用程序,可以在门户环境中运行,展示并...

    portal jsr168

    与Request对象相对应,JSR168也提供了两种Response对象:ActionResponse和RenderResponse。它们用于响应对应的Request类型,可以设置重定向、窗口状态、portlet配置等信息。ActionResponse通常用于设置将要渲染的...

    JSF生命周期及组件开发

    - 可以通过调用`FacesContext.responseComplete()`方法将用户重定向到另一个页面。 - 使用`FacesContext.renderResponse()`重新显示原始视图。 - 忽略某些阶段或合并多个阶段以优化性能。 #### 四、JSF组件开发 ...

    portal开发portlet的一些知识

    图片路径的写法 &lt;IMG &gt;/testportlet/images/mark.gif"&gt; &lt;IMG src="%=renderResponse.encodeURL(renderRequest.getContextPath()+"&gt;"&gt; 其中renderResponse.encodeURL表示编码。目录结构截图: 。。。 。。。

    SPRINGMVCDEMO

    在Spring MVC中,我们可以使用Portlet MVC API来创建portlet,这包括PortletMode、WindowState、ActionRequest、RenderRequest和RenderResponse等接口。 "demo" 文件可能包含了这个Spring MVC Portlet的源代码,...

    IBM portlet开发指南

    Portlet Requests和Portlet Response是Portlet处理HTTP请求和生成响应的对象,它们具有多种类型,如ActionRequest、RenderRequest、ActionResponse、RenderResponse等,各自负责不同类型的请求和响应处理。...

    Access Objects from Velocity

    - `renderRequest`、`renderResponse`:提供了渲染请求和响应的接口。 - `xmlRequest`、`themeDisplay`:提供XML请求数据和主题显示对象。 - `company`、`user`、`realUser`、`layout`:分别提供了对公司对象、用户...

    在JetSpeed中开发portlet项目

    2. JSP页面:portlet视图通常由JSP页面呈现,通过`renderRequest`和`renderResponse`对象传递数据。 3. 表单处理:对于需要用户输入的portlet,可以使用`processAction`方法处理表单提交,并更新视图。 4. 事件处理...

    jsf1.2_src

    - 源码中 `renderResponse` 阶段的处理特别值得关注,这是将组件转换为实际HTML的地方。 5. **EL(表达式语言)与 Managed Beans** - JSF 1.2 集成了Java EE的EL,使得数据绑定变得简单。通过查看源码,我们可以...

    基于PHPWIND插件的体会及编写思路.pdf

    `ModelAndView`中的模型部分可以存放`RenderRequest`和`RenderResponse`对象,以便于在视图层获取这些信息,实现数据的传递和渲染。 ### 实例分析:Spring-Portlet集成 以Web.xml配置为例,可以看到Spring-Portlet...

    Portlet规范之Pluto实现的运用

    它有两个子接口:`ActionResponse`和`RenderResponse`,分别用于处理动作响应和渲染响应。 #### 10. ActionResponseAction响应接口 `ActionResponse`接口继承自`PortletResponse`,用于处理动作请求的响应。开发...

    基于 Struts 2 构建 WebSphere Portal 上的 Portlet 应用

    在 WebSphere Portal 中开发 Portlet,首先需要了解 Portlet API,包括 Portlet、ActionRequest、ActionResponse、RenderRequest 和 RenderResponse 等接口。Portlet 生命周期包括初始化、渲染、动作处理和销毁四个...

    JSR168 PORLET标准手册汉化整理

    3. **渲染协议**:portlet通过renderRequest和renderResponse对象与portlet容器通信,确定如何显示portlet内容。 4. **事件处理**:portlet可以通过订阅和发布事件与其他portlet交互,实现协同工作。 5. **URL管理...

    JSR168_Portlet开发入门

    5. `RenderRequest`和`RenderResponse`:在渲染阶段使用,用于构建最终的HTML页面。 6. `ActionRequest`和`ActionResponse`:处理用户的动作请求,如提交表单或触发某些操作。 7. `EventRequest`和`EventResponse`...

    JSR168+PORLET标准手册

    6. **Portlet通信**:通过`renderRequest`和`renderResponse`对象进行,portlet可以获取请求参数并生成响应。 7. **Action请求和Event处理**:portlet可以通过动作请求(ActionRequest)来处理用户交互,或者通过...

Global site tag (gtag.js) - Google Analytics