问题描述
由于所有 JSP 在执行之前都会生成/转换为 Servlet,因此对于 Facelets 也是如此吗?
As all JSPs are generated / translated to Servlets before their execution, is its true for Facelets too?
我正在使用 JSF 2.0 和 Facelets,并希望查看其生成的 Java 代码(可能是 Servlet).
I am working with JSF 2.0 and Facelets and wanted to see its generated Java Code which might be Servlet.
推荐答案
不,Facelets 文件使用 SAX 解析器.XML 树存储在 Facelet 缓存.XML 树在 视图构建时间变成了UIComponent
树,可通过 FacesContext#getViewRoot()
(你可以通过 getChildren()
在运行时).组件树通常通过它们自己的 encodeXxx()
方法或关联的 Renderer
,以 UIViewRoot#encodeAll()
.
No, Facelets files are parsed to a XML tree using a SAX parser. The XML tree is stored in the Facelet cache. The XML tree is during view build time turned into an UIComponent
tree which is accessible by FacesContext#getViewRoot()
(which you can traverse by getChildren()
during runtime). The component tree normally generates HTML code by their own encodeXxx()
methods or the ones on the associated Renderer
, starting with UIViewRoot#encodeAll()
.
Facelets 文件不生成任何类文件.XML 树默认存储在服务器的内存中.但是,从 JSF 2.1 开始,您可以指定自定义 FaceletCache
由 在
faces-config.xml
中实现,您可以在其中编写代码来存储 XML 树例如在磁盘文件系统上(虽然会更慢).
Facelets files do not generate any class files. The XML trees are by default stored in server's memory. Since JSF 2.1 you can however specify a custom FaceletCache
implementation by <facelet-cache-factory>
in faces-config.xml
wherein you can write code to store the XML tree on for example the disk file system (which would be slower, though).
如果你在视图中使用并打开它,那么你可以看到
UIViewRoot
后面的组件树的文本表示.另请参阅如何调试 JSF/EL
If you use <ui:debug>
in the view and open it, then you can see the textual representation of the component tree behind UIViewRoot
. See also how to debug JSF/EL
- 为什么不是 JSF 页面是预编译的(至少是部分),而是在每次构建视图时进行解析和评估?
- 视图构建时间是多少?
- 测量渲染时间服务器请求后的 JSF 视图
- 为什么从 JSF2.0 开始,Facelets 优于 JSP 作为视图定义语言?
这篇关于Facelets页面是否像JSP生成给Servlet那样生成给Servlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!