资源预览内容
第1页 / 共110页
第2页 / 共110页
第3页 / 共110页
第4页 / 共110页
第5页 / 共110页
第6页 / 共110页
第7页 / 共110页
第8页 / 共110页
第9页 / 共110页
第10页 / 共110页
亲,该文档总共110页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
深入浅出JSF框架,BOS分析设计部 葛朋旭,序言,JSF作为JavaEE的标准Web框架 发展历程 1.0-1.1-1.2-2.0 IBM, Oracle,开源社区有多种实现版本 AOM、WAF的底层核心就是JSF框架 JSF的标准规范 JSF的框架原理 JSF生命周期分析 JSF的高级特性 JSF的RIA技术整合 JSF的新版本趋势,提纲,JSF标准规范 框架设计原理 生命周期跟踪 高级特性分析 RIA技术整合 新版本趋势,JSF流行曲,Application Development Technologies One-Tier Two-Tier Multi-Tier Todays Application Development Frameworks Tapestry, Struts, Webwork, Hibernate, TopLink, ADF UIX,Spring, What is JSF? JavaServer Faces (JSF) is a user interface (UI) framework for Java Web applications. It is designed to significantly ease the burden of writing and maintaining applications that run on a Java application server and render their UIs back to a target client.,JSF流行曲,JSF Developer Type Page author Application developer Component writer Tools provider JSF implementers,提纲,JSF标准规范 框架设计原理 生命周期跟踪 高级特性分析 RIA技术整合 新版本趋势,JSF标准规范- JSF有什么,JSR-127 Standard specification JDK1.5 Java Servlet 2.5 JavaServerTM Pages 2.1 JavaServerTM Pages Standard Tag Library 2.1 Component Model Event Driven Navigation Model Application Lifecycle 架构跟协议、Makeup的无关性,提纲,JSF标准规范 框架设计原理 生命周期跟踪 高级特性分析 RIA技术整合 新版本趋势,JSF Architecture,MVC,JSF Architecture,MVC Model 2,JSF Architecture,MVC Model 2 Struts model2,JSF Architecture,MVC Model 2 Struts model2 JSF model2,JSF Architecture,Model 2 Pattern【MVC】 Model Managed Bean/Backing beans JavaScript Model View UIComponent DHTML/DOM/CSS (XML)based, WML-based Controller FacesServlet JavaScript Controlller,Component-Based UI Framework,UIComponent Renderer RenderKit Renderer-specific component subclass JSP tag/ Facelets,JSF UIComponent,1.1,JSF UIComponent,1.1 1.2 UINamingContainer,JSF 框架分析-1,Saving and Restoring State StateManager ResponseStateManager javax.faces.ViewState Component Family and Component Type Converters,Validators, Events, and Listeners Facets,JSF 框架分析-2,Renderers decode encode,JSF 框架分析-2,Renderers Renderer Types,JSF 框架分析-2,Renderers Renderer Types RenderKits HTML SVG, WML, Ajax, XUL Microsofts DHTML/HTML Components (HTC) Mozillas XUL/XML Binding Language (XBL) Custom Action Tag Handlers,提纲,JSF标准规范 框架设计原理 生命周期跟踪 高级特性分析 RIA技术整合 新版本趋势,JSF Development,Building an Application Using JSF 创建ManagedBean 编写View页面 配置faces-config.xml,JSF Request Process,接收到一个jsf Request时,JSF implementation启动,相应的processes/services必须在portal/servlet环境可用,为此JSF实现调用不同的工厂类完成各方面的职责。 Web Application Start-Up 一个 JSF Web application 启动, 4个工厂被实例化 ApplicationFactory 创建Application实例,Lifecycle instance to create and restore JSF views。 LifecycleFactory returning a Lifecycle instance for a lifecycle identifier RenderKitFactory returning a RenderKit for the JSF Web application FacesContextFactory create an instance of FacesContext that is used to represent contextual information associated with the incoming request and eventually with the response,JSF Lifecycle,Request-Processing Lifecycle 1 Restore View 2 Apply Request Values 3 Process Validations 4 Update Model Values 5 Invoke Application 6 Render Response,Lifecycle Web Start-up,启动阶段,Lifecycle Web Start-up,启动阶段 facesServlet内部创建 FacesContextFactory LifecycleFactory 每个JSF Web程序 一个ApplicationFactory 每个JSF implementation,有一个缺省 RenderKit,Lifecycle - Restore View Phase,Restore View Phase ViewHandler.restoreView() restoring a view from the server and client state 如果 ViewHandler.restoreView() 返回null 调用FacesContext的renderResponse() 否则 调用 ViewHandler.createView() 创建UIViewRoot,并绑定到FaceConext,Lifecycle - Render Response Phase,步骤1 调用ViewHandler.renderView() 执行JSP文档 从UIViewRoot中获取到viewId值,传递给方法ExternalContext.dispatch() dispatch方法再forward 相应 viewId的值给Web容器,Lifecycle - Render Response Phase,步骤2 JSF-specific不负责forwarded request 被FaceServlet忽略的request将传给JSP容器 JSP容器将按顺序,根据上下文的相对路径,执行跟viewId匹配的JSP页面,Lifecycle - Render Response Phase,步骤3 在处理、执行JSF的JSP页面前,JSP引擎检测所用的content typetext/html和character encodingUTF-8 标签优先展示 作为所有JSF组件的容器 创建、保存一个 ResponseWriter实例在 FacesContext中 ResponseWriter将输出客户端的标签 缺省的 RenderKit HTMLRenderKit 要求content type 必须为text/html JSF component 被创建,并绑定到组件层次树上 如:对应HtmlForm,Lifecycle - Render Response Phase,步骤4 JSF JSP tag 调用Application.createComponent()方法该方法以一个字符表示component type 如:javax.faces.HtmlForm component type被映射到faces-config.xml中定义的一个类 一个HtmlForm 组件将被创建并绑定到 UIViewRoot 通过component family和renderer type来定位一个具体的Renderer tag调用组件的 encodeBegin()方法 相应调用HtmlForm renderer的encodeBegin() 方法 方法输出代码,Lifecycle - Render Response Phase,步骤5 在中所有嵌套的组件都会被创建并render并添加到中。 tag被执行 将调用Renderer的 encodeEnd() 调用ViewHandler 的writeState() 传递 a token 给 ResponseWriterjsf1.2之前的做法 encodeEnd()方法输出 最后输出 JSF1.2 component hierarchy 先创建,再输出展示,Lifecycle Postback Request,Postback Scenario 用户在接收到初始请求页面后, 输入、提交数据。 How JSF handles postback 6个生命周期被调用 或者FacesContext.renderResponse()来跳过某个 跟initial request的不同之处在于第一、最后一个阶段,Lifecycle JSF handles postback,1 Restore View Phase 跟Init Request相同 调用ViewHandler的restoreView方法,保存此前请求的任何状态变量。 差异性 restoreView()不再返回null,而是返回跟viewId相关的当前组件树状态。 如果STATE_SAVING_METHOD设置为client-side保存,回复的组件树将传递给FacesContext,Lifecycle JSF handles postback,2 Apply Request Values Phase 每个input组件从请求参数中建立submitted value 每个comm
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号