Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Facelets page generated to Servlet as JSP generated to Servlet

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.

like image 532
Faisal Basra Avatar asked Nov 01 '12 08:11

Faisal Basra


People also ask

What is difference between JSP and servlet?

Servlets are faster as compared to JSP, as they have a short response time. JSP is slower than Servlets, as the first step in the JSP lifecycle is the conversion of JSP to Java code and then the compilation of the code. Servlets are Java-based codes. JSP are HTML-based codes.

What is the difference between JSF and JSP?

JSF is a web-based application that is used to simplify the development integration of web-based user interfaces. While JSP is a Java-based technology used respectively in order to support software developers create dynamic web pages. JSP must be compiled in Java bytecode in order to work properly.

Which file format do you use for facelets?

Facelets views are usually created as XHTML pages. JavaServer Faces implementations support XHTML pages created in conformance with the XHTML Transitional DTD, as listed at http://www.w3.org/TR/xhtml1/#a_dtd_XHTML-1.0-Transitional. By convention, web pages built with XHTML have an . xhtml extension.

Which language is used to write servlets and JSP?

Servlets are written in the Java language. JSPs on the other hand use a combination of HTML and Java. Eventually JSPs are converted into a pure Java servlet.


2 Answers

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?
like image 113
BalusC Avatar answered Sep 21 '22 13:09

BalusC


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

like image 39
Bozho Avatar answered Sep 22 '22 13:09

Bozho