7

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.

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
Faisal Basra
  • 1,564
  • 4
  • 23
  • 38

2 Answers2

13

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:

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
1

Not exactly the same way, it gets cached. But it doesn't generate servlet code.

Bozho
  • 554,002
  • 136
  • 1,025
  • 1,121