问题
As all JSPs are generated / translated to Servlets before their execution, is its true for Facelets too?
I am working with JSF 2.0 and Facelets and wanted to see its generated Java Code which might be Servlet.
回答1:
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 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).
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
See also:
- 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?
回答2:
Not exactly the same way, it gets cached. But it doesn't generate servlet code.
来源:https://stackoverflow.com/questions/13173633/is-facelets-page-generated-to-servlet-as-jsp-generated-to-servlet