JSF 源代码赏析之Lifecycle
来源:互联网 发布:校园网络诈骗案例 编辑:程序博客网 时间:2024/04/28 16:50
JSF 源代码赏析之Lifecycle
关键字: jsf sourcecode lifecycle
JSF的生命周期在JSF应用中起着至关重要的作用,每一个JSF请求的处理都需要经过一次生命周期,本文从源码的角度分析JSF的生命周期。
在讨论生命周期之前,我们先要讨论FacesContext的一些元素,他们在整个生命周期中扮演了非常重要的角色。么个JSF应用必须保存它所处理的请求信息,FacesContext为处理请求和生成响应保存了所有必需的上下文信息,具体而言,它包括:
1.信息队列,MessageQueue,保存所有的消息
2.当前的组件树,ViewRoot,
3.外部上下文,ExternalContext
4.Application。
下面就是Sun的FacesContextImpl中的变量:
这里面有很多重要的对象值得我们去研究,按照从上到下的顺序,我们先来看看ExternalContext。
ExternalContext其实是对ServletContext(或PortletContext)的封装,提供了访问外部容器资源的各种方法,ExternalContext基类定义如下:
在讨论生命周期之前,我们先要讨论FacesContext的一些元素,他们在整个生命周期中扮演了非常重要的角色。么个JSF应用必须保存它所处理的请求信息,FacesContext为处理请求和生成响应保存了所有必需的上下文信息,具体而言,它包括:
1.信息队列,MessageQueue,保存所有的消息
2.当前的组件树,ViewRoot,
3.外部上下文,ExternalContext
4.Application。
下面就是Sun的FacesContextImpl中的变量:
com.sun.faces.context.FacesContextImpl:
这里面有很多重要的对象值得我们去研究,按照从上到下的顺序,我们先来看看ExternalContext。
ExternalContext其实是对ServletContext(或PortletContext)的封装,提供了访问外部容器资源的各种方法,ExternalContext基类定义如下:
javax.faces.context.ExternalContext:
- public abstract class ExternalContext {
- public static final String BASIC_AUTH = "BASIC";
- public static final String CLIENT_CERT_AUTH = "CLIENT_CERT";
- public static final String DIGEST_AUTH = "DIGEST";
- public static final String FORM_AUTH = "FORM";
- // ---------------------------------------------------------- Public Methods
- public abstract void dispatch(String path)
- throws IOException;
- public abstract String encodeActionURL(String url);
- public abstract String encodeNamespace(String name);
- public abstract String encodeResourceURL(String url);
- public abstract String getAuthType();
- public abstract Object getContext();
- public abstract String getInitParameter(String name);
- public abstract Map getInitParameterMap();
- public abstract String getRemoteUser();
- public abstract Object getRequest();
- public void setRequest(Object request) {
- ExternalContext impl;
- if (null != (impl = (ExternalContext) this.getRequestMap().
- get("com.sun.faces.ExternalContextImpl"))) {
- impl.setRequest(request);
- return;
- }
- throw new UnsupportedOperationException();
- }
- public void setRequestCharacterEncoding(String encoding) throws UnsupportedEncodingException {
- ExternalContext impl;
- if (null != (impl = (ExternalContext) this.getRequestMap().
- get("com.sun.faces.ExternalContextImpl"))) {
- impl.setRequestCharacterEncoding(encoding);
- return;
- }
- throw new UnsupportedOperationException();
- }
- public abstract String getRequestContextPath();
- public abstract Locale getRequestLocale();
- public abstract Iterator<locale></locale> getRequestLocales();
- public abstract Iterator<string></string> getRequestParameterNames();
- public abstract String getRequestPathInfo();
- public abstract String getRequestServletPath();
- public String getRequestCharacterEncoding() {
- ExternalContext impl;
- if (null != (impl = (ExternalContext) this.getRequestMap().
- get("com.sun.faces.ExternalContextImpl"))) {
- //noinspection TailRecursion
- return impl.getRequestCharacterEncoding();
- }
- throw new UnsupportedOperationException();
- }
- public String getRequestContentType() {
- ExternalContext impl;
- if (null != (impl = (ExternalContext) this.getRequestMap().
- get("com.sun.faces.ExternalContextImpl"))) {
- //noinspection TailRecursion
- return impl.getRequestContentType();
- }
- throw new UnsupportedOperationException();
- }
- public String getResponseCharacterEncoding() {
- ExternalContext impl;
- if (null != (impl = (ExternalContext) this.getRequestMap().
- get("com.sun.faces.ExternalContextImpl"))) {
- //noinspection TailRecursion
- return impl.getResponseCharacterEncoding();
- }
- throw new UnsupportedOperationException();
- }
- public String getResponseContentType() {
- ExternalContext impl;
- if (null != (impl = (ExternalContext) this.getRequestMap().
- get("com.sun.faces.ExternalContextImpl"))) {
- //noinspection TailRecursion
- return impl.getResponseContentType();
- }
- throw new UnsupportedOperationException();
- }
- public abstract URL getResource(String path) throws MalformedURLException;
- public abstract InputStream getResourceAsStream(String path);
- public abstract Set<string></string> getResourcePaths(String path);
- public abstract Object getResponse();
- public abstract Object getSession(boolean create);
- public abstract Principal getUserPrincipal();
- public abstract boolean isUserInRole(String role);
- public abstract void log(String message, Throwable exception);
- public abstract void redirect(String url) throws IOException;
- }
这个抽象类共有1000多行,提供了访问外部资源的各种方法,主要是对ServletContext或是PortletContext中方法的封装,比如getRemoteUser、getRequest、getSession等方法都是很常用的,但是在运用时也要注意,如果在程序中写死是ServletContext或HttpServletRequest,那么以后对于更换到Portal环境中是不利的,这个如果需要转换的话需要注意了。
下面来看看Application对象。Application对象是应用系统范围内的单例类,提供了对FacesContext文件的对象封装,从这个对象中可以得到很多FacesContext文件中的配置,还是来看看定义吧.
- JSF 源代码赏析之Lifecycle
- JSF 源代码赏析之FacesServlet
- 开源代码赏析之find_next_bit函数
- The JSF application lifecycle
- jsf lifecycle and 4 events
- 代码之美——Doom3源代码赏析
- 代码之美——Doom3源代码赏析
- 代码之美——Doom3源代码赏析
- 代码之美——Doom3源代码赏析
- 代码之美——Doom3源代码赏析
- 代码之美——Doom3源代码赏析
- 代码之美——Doom3源代码赏析
- 转:代码之美——Doom3源代码赏析
- Normalize.css源代码赏析
- 佛祖保佑源代码赏析
- android 之 Activity lifecycle
- android lifecycle之onpause
- maven 之 build lifecycle
- 有电脑,没宽带,也能上网。
- Symbian 程序隐藏的某些办法
- SQL数据库中用image来存储文件
- Silverlight入门学习(35)
- MPEG-2TS码流编辑的原理及其应用
- JSF 源代码赏析之Lifecycle
- ASP.NET2.0页面打开时乱码解决方法-HTTP 閿欒 404 - Not Found銆?/i>
- 利用HttpWebRequest类Post数据至URI
- 用线性时间算法建立二叉堆。
- 存储过程
- jQuery 1.4
- 手机开发平台指南、教程和资料介绍(修改稿)
- Maven2完全使用手册
- 转载李嘉诚先生曾经写的一首激励他的员工的诗,送给大家!