gpt4 book ai didi

jsf - Facelets页面是否像JSP生成给Servlet那样生成给Servlet

转载 作者:行者123 更新时间:2023-12-04 10:19:38 25 4
gpt4 key购买 nike

由于所有 JSP 在执行之前都会生成/转换为 Servlet,因此 Facelets 也是如此吗?

我正在使用 JSF 2.0 和 Facelets,并希望看到它生成的 Java 代码,它可能是 Servlet。

最佳答案

不,Facelets 文件使用 SAX parser 解析为 XML 树。 . XML 树存储在 Facelet cache 中. XML 树在 view build time 期间变成了 UIComponent 可通过 FacesContext#getViewRoot() 访问的树(您可以在运行时通过 getChildren() 遍历)。组件树通常由自己生成 HTML 代码 encodeXxx()方法或相关联的方法 Renderer ,以 UIViewRoot#encodeAll() 开头.
Facelets 文件 不要生成任何类文件。 XML 树默认存储在服务器的内存中。但是,从 JSF 2.1 开始,您可以指定自定义 FaceletCache 实现者 <facelet-cache-factory>faces-config.xml您可以在其中编写代码以将 XML 树存储在例如磁盘文件系统上(虽然这会更慢)。
如果您使用 <ui:debug>在 View 中打开,可以看到UIViewRoot后面的组件树的文字表示.另见 how to debug JSF/EL
也可以看看:

  • Why not JSF pages are precompiled (atleast partially) but instead parsed, evaluated each time view is built?
  • What's the view build time?
  • Measure the render time of a JSF view after a server request
  • Why Facelets is preferred over JSP as the view definition language from JSF2.0 onwards?
  • 关于jsf - Facelets页面是否像JSP生成给Servlet那样生成给Servlet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13173633/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com