JSF vs Facelets vs JSP

Pam picture Pam · Jan 27, 2011 · Viewed 79.6k times · Source

I can't seem to get a clear answer as to the concrete difference between Java Server Faces vs. so-called facelets. Can anyone give me a clear-as-day answer?!?

Also, I understand that either JSF or JSP can be used to create dynamic web pages, but two seemingly-conflicting details are confusing me. I've heard both of the following:

  1. That JSF is a replacement for JSP; and

  2. JSF and JSP form different parts of the View in Java's web-tier MVC paradigm

So which is it? Logic dictates it almost certainly can't be both!

Answer

Michael Borgwardt picture Michael Borgwardt · Jan 27, 2011
  • JSF is a standardized Java framework for web UIs based on an MVC pattern
  • JSPs are a (much older) standard for generating web pages from templates - these can be used as the View in a JSF application, but also separately from JSF.
  • Facelets are an alternative view technology based on pure XML templates (no scriptlets) which was introduced with Version 2 of the JSF standard. They can only be used in a JSF application.

In the light of that, let's take a look at your conflicting statements:

That JSF is a replacement for JSP; and

Not quite true, since JSF can use JSPs for its view (and had to, prior to JSF 2). However, JSF apps using Facelets can be seen as a replacement for JSP-based technologies.

JSF and JSP form different parts of the View in Java's web-tier MVC paradigm

Completely wrong - JSF covers the entire MVC pattern (though it can overlap with EJBs, since both are based on annotations that can be mixed in the same class).