JSF在那里加载JSF实现类?
lvbaosong
2008-10-15
这两天研究JSF源码但咋找也找不到JSF是在那里初始化并加载有JSF实现者提供的实现类,比如ApplicationFactoryImpl,FacesContextFactoryImpl.
|
|
JSF狂人
2008-10-16
jsf下的所有bean,不管是request的还是application范围的,都是不访问不创建实例不加载。也就是说,如果你的项目启动了,但是你没有实际意义上的真正访问此bean,如
#{applicationBean.str} 就不会初始化bean 这点跟spring也算是取大的区别 spring是在项目启动时就加载,不管你是否访问,都会创建实例。 打个比方: 当tomcat启动后,这时spring管理的bean已经实例化并且加载到内存里了 当你访问你的项目时,如http://127.0.0.1:8080/jsf/index.jsf并且index.jsf里有类似于#{applicationBean.str}的访问相关bean的代码时,才会实例化其相关的bena 呵呵,跑题了! 你可以看看以下代码?很了理解,我就不再解释了。 public Object evaluateExpressionGet (FacesContext context, String expression, Class expectedType) throws ELException { Application app = getRIApplicationImpl(context); if (app != null) return app.evaluateExpressionGet(context, expression, expectedType); throw new UnsupportedOperationException(); } private static Application getRIApplicationImpl(FacesContext context) { ExternalContext extContext; if (context != null) extContext = context.getExternalContext(); else extContext = FacesContext.getCurrentInstance().getExternalContext(); if (extContext != null) return (Application) extContext.getApplicationMap() .get("com.sun.faces.ApplicationImpl"); return null; } 其实说到最后,不跟spring一样,不都是个map嘛! 但是加载时间上有区别。 最后补充一句,我说的是sun的实现,从com.sun.faces.ApplicationImpl可以看出来 |
|
lvbaosong
2008-10-17
我说的是JSF规范中所没实现的那些由提供商提供的实现类是在那里加载的。比如jsf规范中会有四大工厂抽象类,具体实现是在JSF-RI中给出的具体实现类,如ApplicationFactoryImpl,FacesContextFactoryImpl,等。这些工厂类应该是在应用加载后在init中进行初始化,但我没找到加载配置文件的地方。
|
|
zwszwszzz
2008-10-20
在具体的实现包里的meta-inf下会有tld文件,web服务器启动时会加载所有jar文件里的tld文件,这是web服务器规范规定的,这个tld和web.xml类似,看了就知道怎么加载的了
|
|
zwszwszzz
2008-10-20
sun的参考实现:jsf_core.tld中的
<listener> <listener-class>com.sun.faces.config.ConfigureListener</listener-class> </listener> |
|
mfkvfn
2011-02-24
可以看下FacesServlet.java的init()方法。
/** * <p>Acquire the factory instances we will require.</p> * * @throws ServletException if, for any reason, the startup of * this Faces application failed. This includes errors in the * config file that is parsed before or during the processing of * this <code>init()</code> method. */ public void init(ServletConfig servletConfig) throws ServletException { // Save our ServletConfig instance this.servletConfig = servletConfig; // Acquire our FacesContextFactory instance try { facesContextFactory = (FacesContextFactory) FactoryFinder.getFactory (FactoryFinder.FACES_CONTEXT_FACTORY); } catch (FacesException e) { Throwable rootCause = e.getCause(); if (rootCause == null) { throw e; } else { throw new ServletException(e.getMessage(), rootCause); } } // Acquire our Lifecycle instance try { LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); String lifecycleId ; // First look in the servlet init-param set if (null == (lifecycleId = servletConfig.getInitParameter(LIFECYCLE_ID_ATTR))) { // If not found, look in the context-param set lifecycleId = servletConfig.getServletContext().getInitParameter (LIFECYCLE_ID_ATTR); } if (lifecycleId == null) { lifecycleId = LifecycleFactory.DEFAULT_LIFECYCLE; } lifecycle = lifecycleFactory.getLifecycle(lifecycleId); } catch (FacesException e) { Throwable rootCause = e.getCause(); if (rootCause == null) { throw e; } else { throw new ServletException(e.getMessage(), rootCause); } } } |