In a MVC web app, servlet and JSP is like the controller and view. Whereas JSF the stuff you write is model (managed beans) and view, the controller is the FacesServlet provided.
JSF is a "component"-based framework.
When to use which depends on the complexity of the UI design. For example, if there is a table that requires column sorting, pagination, or dynamic row editing then JSF is better. JSP will take much more effort in implementing those features.
I am far from a JSF expert, but here is my 2 cents.
It comes down to the complexity of your model and the UI requirements - cost vs benefits.
JSP is easier than JSF, but won't do as much.
Guidelines I would consider:
No/Minimal UI - servlets.
Simple UI - JSP
Complicated/Component based UI - JSF
SimpleUI - JSP with a tag library like JSTL (no scriptlets)
Relatively simple HTML pages
- one "domain" of model information being shown
- simple conditional / looping logic that can easily be expressed in HTML
Complicate UI - JSF
- multiple "sections" of a screen. i.e. dashboard type interface
- more complicated object model
- more complicated input paradigms - formatters.
One thing to note about JSF - it puts a lot of emphasis on data input from forms. One of the greatest conveniences of JSF is that it validates every data item on the form and will refuse to process until each and every input control contains a valid value. If one or more control values is invalid, the form is re-displayed with the user input (no need for the user to re-enter the data) and it's an easy thing to design forms where the error messages for a control are displayed next to the control itself. Which is very much preferable to the lazy forms I routinely see that basically say "One or more values on this page are in error. Please correct them and resubmit". About the only thing that approaches that level of annoyance to me are fields for long numbers that cannot allow dashes or spaces in them .
But there's one very important thing to note. Ultimately, it's not about JSP/servlet versus JSF, it's about whether to use JSF or not. JSF does not forbid the presence of non-JSF servlets or JSPs in the same webapp. In fact, one of the most common admonitions I make in the JSF forum is against trying to force JSF to output XML or non-HTML documents such as Excel spreadsheets, Word Documents or PDFs. JSF is not intended for those purposes, so while it can be done, it's simpler to do those parts of the webapp without JSF.
JSF is not a jealous all-or-nothing architecture. JSF code can live in perfect harmony not only with JSP/servlet code, but Spring Web, Struts, Apache CXF web services, and more all in the same webapp.
"privilege" comes from the Latin words for "private" and "law" (legal) and dates to feudal times. To "claim privilege" meant that you were above the laws that applied to the common people.
What are you saying? I thought you said that Santa gave you that. And this tiny ad: