×
☰ See All Chapters

JSF Tutorial

  • JSF (Java Server Faces) is a component based MVC web application framework which is built on top of the Servlet API and provides components in favor of taglibs, which can be used in JSP or any other Java based view technology such as Facelets.  

  • JSF framework is similar to Struts from Apache, Spring MVC from spring community.   

  • Framework is a special software, that is developed based on core technologies having capability to develop the common logics of the application development dynamically. This process makes application developer to just concentrate on application specific logics development. This increases the productivity in application development. Doing more work in less time with good accuracy is called good productivity.  

  • JSF1.X is a web framework released by SUN microsystem in 2004.  

  • JSF2.X is a specification and web framework developed by JCP. Java Server Faces (JSF2.X) is a JCP Standard technology for authoring component based user interfaces on the Java EE platform. JCP is a Java Community Process which includes experts groups like Apache, Oracle, IBM etc…  

  • Prior to JSF 2.0, JSP was used as a View Declaration Language for JSF. 

  • In JSF 2.0, facelets are incorporated into the core JSF specification. 

What is the difference between JSF, Servlet and JSP?

Below table lists out the difference between JSF, Servlet and JSP also advantages of JSF over Servlet and JSP

Servlet and JSP

JSF

No built in MVC support

Built in MVC support

Developer has to collect data from request and transfer into object.

Data is collected and transferred into objects of Managed Bean.

No input data validation is present, developer has to write separate code for data validation(server side validation) or have to use JavaScript (client side validation)

Has built in support for input data validation. Both server side validation (using no external support) and client side validation (using Primefaces , RichFaces…)

Servlet/Jsp is invasive because, programmer has to extend HttpServlet abstract class or implement Servlet Interface

JSF is non-invasive because, it doesn’t force a programmer to extend or implement their class from any predefined class or interface given by JSF API,

UI support is poor, for providing rich UI developer has to write Custom tags in JSP.

It provides rich UI support because it can integrate with 3’rd party UI frameworks like Primefaces, RichFaces, Ice faces….

In Servlet/JSP input data can be obtained only in String or in Object type. We have to type cast the data explicitly to required data type.

Has built in data conversion to required type which happens automatically.

For internationalization developer has to write code explicitly which will be complex

Achieving internationalization in JSF is easy.

In servlet/JSP programmer has to take care about providing response to different type of clients. Programmer has to write HTML code to give response to desktop browser and also has to write WML(wireless markup language) code to give response to smartphones.

JSF has RenderKit. RenderKit is a class which represents a collection of Renderer instances that, together, know how to render JavaServer Faces-UIComponent instances for a specific client. Hence JSF has automatic generation of appropriate output for the target client, taking into account all available client configuration data, such as browser version, etc.

Client side event, sever side listeners is not present.

Event Driven. Has events and listeners on both client and server side.

No built in Ajax support.

Has built-in support for Ajax

 


All Chapters
Author