33

I am trying to get familiar with Java EE 6 by reading http://java.sun.com/javaee/6/docs/tutorial/doc/gexaf.html. I am a bit confused about the use of JSF.
Usually, the way I develop my Web App would be, Servlet would act like a controller and JSP would act like a View in an MVC model. So Does JSF try to replace this structure? Below are the quote from the above tutorial:

Servlet are best suited for service-oriented App and control function of presentation-oriented App like dispatching request
JSF and Facelet are more appropriated for generating mark-up like XHTML, and generally used for presentation-oriented App

Not sure if I understand the above quote too well, they did not explain too well what is service-oriented vs presentation-oriented.

A JavaServer Faces application can map HTTP requests to component-specific event handling and manage components as stateful objects on the server.

Any knowledgeable Java developer out there can give me a quick overview about JSF, JSP and Servlet? Do I integrate them all, or do I use them separated base on the App? if so then what kind of app use JSF in contrast with Servlet and JSP

A JavaServer Faces application can map HTTP requests to component-specific event handling and manage components as stateful objects on the server.

Sound like what servlet can do, but not sure about manage components as stateful objects on the server. Not even sure what that mean? Thanks in advance.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Thang Pham
  • 38,125
  • 75
  • 201
  • 285

5 Answers5

31

JSF basically enables you to develop a web application with only model objects (JavaBeans) and views (JSP/XHTML pages). With "plain vanilla" JSP/Servlet you'll have to bring in a lot of code to control, preprocess, postprocess, gather data, validate, convert, listen, etc the HTTP request and response. And then I'm not talking about refactoring it to a high (abstract) degree so that you can also end up the same way as JSF does (just a JavaBean class and a JSP/XHTML page per use case).

I've posted a more detailed answer on the subject before here: What is the difference between JSF, Servlet and JSP?

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 1
    Srry I should have look before I posted. Will definitely read your post. But from what I am reading now. JSF is more like a framework that hide lot of implementations from the developer, and in a way, a bit better then Servlet/JSP. Am I right? – Thang Pham Apr 23 '10 at 18:49
  • 7
    JSP/Servlet is just the *basic/core/buildstone* technology to develop Java webapplications with. Any Java based MVC framework runs on top of the JSP/Servlet API, so also JSF. JSF provides the `FacesServlet` (yes, it's a servlet!) which you have to define in `web.xml` just once. Then you can develop/run JSF with only model objects and views. – BalusC Apr 23 '10 at 19:01
  • Right... from what you posted on the other thread, JSF is a MVC web framework. Can I compare JSF to Spring MVC, BalusC? – Thang Pham Apr 26 '10 at 21:17
  • 3
    They are indeed competitors. There are however not as many component libraries available for Spring MVC as for JSF. – BalusC Apr 26 '10 at 21:52
  • 1
    It is just weird since people always talk about Spring MVC, not much about JSF. I was think about doing a on site training on this technology, and still undecided about between Spring and JSF. I only want to pick one since the training is quite pricy. Do you have any professional opinion for me BalusC? – Thang Pham Apr 28 '10 at 19:50
  • 3
    Note that "Spring" != "Spring MVC". The Spring Framework is many, many more than just Spring MVC. With regard to Spring MVC versus JSF: well, look around for job trends in your neighbourhood. Choose the one which is the most asked and/or the best paid. You can always learn the other framework in private/hobby time. – BalusC Apr 28 '10 at 20:06
  • Hi BalusC, I hope you dont mind if I ask you a question. I remember you wrote an article about how to increase web performance using some yahoo tool for Java EE user, but I cant seems to find the link. Do you know what article I am talking about? If you do, you mind give the link to me – Thang Pham Jan 27 '11 at 04:30
  • 3
    @Harry: http://balusc.blogspot.com/2009/09/webapplication-performance-tips-and.html – BalusC Jan 27 '11 at 04:31
10

In JSF uses one specific Servlet (the Faces Servlet) to handle all incoming requests and dispatch them to the appropriate beans.

JSF is a component-based MVC framework, while JSP is a view technology.
You can use JSP with JSF, although Facelets is the preferred view technology.

informatik01
  • 16,038
  • 10
  • 74
  • 104
Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
4

JSF provide an abstraction layer with several responsibilities, but most important it handles all the messy details of HTML forms and transferring data back and forth between web pages and Java POJO beans (getX, setX methods), which is notoriously difficult to do right.

It also provides navigation and in the latest incarnation in Java EE 6 rudimentary AJAX support is available allowing for simple updates of the web page as the user inputs data.

You might find it easier to think of it as a way to avoid writing JavaScript yourself.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
  • Javascript has become so much faster in term of performance for the last year and a half. And seem like you only at the beginning of these trend, and now with the development of html5, so do we really want to move away from javascript? – Thang Pham Apr 23 '10 at 18:58
  • He didn't say move away from JavaScript. Using JSF along with a decent component library likes Richfaces or Icefaces means you will be coding quite a bit less JS yourself. – Naganalf Apr 23 '10 at 19:31
3

If you like XML choose JSF. In case that you are an actionlistener fan doPost,doGet etc choose Servlet and JSP.

Chris
  • 31
  • 1
2

JSF Framework targets to simplify development integration of web-based user interfaces. As @bozho stated you can mix JSP and JSF. However, the "view" component in JSF is facelets - which can be viewed as little UI widgets, which are more or less self contained with respect to DHTML styling and JavaScript event generation and call back.

"Should I bother learning.. ?"

Not sure. I haven't seen JSF picking up that much steam even though it was around (Atleast in theory) for last 5 years.

ring bearer
  • 20,383
  • 7
  • 59
  • 72