Thursday, June 17, 2010

Quick Understanding of Java Server Faces (JSF)

I would like to share my experience when I started work on JSF specification. I have development experience on portlets using JSR-168 and I tried to search technical notes which helps me to understand the JSF specification for portlet development. In my searching, I am not able to get any helpful technical note. Here, I am trying to describe all the things which I have learn t for JSF portlet development.

In this post, I will cover the basics of JSF and in other posts I will cover other features of JSF with examples.

Why we use JSF?

Before introducing Java Server Faces, developers who built web applications often relied on building HTML user interface components with portlets or servlets or Java Server Pages (JSP pages). This is mainly because HTML user interface components are the lowest common denominator that web browsers support. The implication, of course, is that such web applications do not have rich user interfaces, compared with standalone fat clients, and therefore less functionality and/or poor usability.

For years ago, Microsoft has evangelized the benefits of drag-and-drop support when advertising their Visual Basic product which provides quick and easy to build applications. JSF provides the same kind of development approach in multi-threaded environment.

What is JSF?

Java Server Faces (JSF) is a very powerful, component-based technology that is being led by Sun Microsystems as JSR 127 under the Java Community Process (JCP). JSF is a user interface (UI) framework for web-applications. JSF lets you build web applications that run on a Java server and render the user interface back to the client. This technology provides web application life cycle management through a controller, and a rich component model with event handling and component rendering. JSF provides standard specification for building User Interfaces for server side applications.

Java Server Faces technology is based on the Model View Controller (MVC) architecture for separating logic from presentation, so if you have been practicing this, you'll feel at home with JSF.

What are the benefits of JSF?

1) Benefits over Software vendors
Several software vendors have updated their toolkits to support JSF, promising rapid development and ease of use through drag-and-drop support when creating JSF-based web applications.

2) Benefits over rich user interface tools
There are a number of options out there today for building rich server-side user interfaces, such as Flash, Swinglets, and Jade. However, these solutions are proprietary; the tools and runtimes that support their development are usually only available through a single vendor. JSF is, above all, a standard, which means that the developer does not get locked into a single vendor.

3) Benefits over different components
Component Vendors provide reusable building blocks for application development and integration into JSF-based tools. Components cover a wide range of uses including reporting, charts and graphs, fields, and navigational components. Here are some of the vendors who offer components that support the Java Server Faces specification.

1) Otrix WebMenu
2) ILOG JViews
3) Quest Software JClass
4) Software FX Chart FX

4) Benefits at User level
Several types of users can benefit from this technology, including:
1) Page authors who use markup languages, such as HTML, will use the JSP tag library for expressing JavaServer Faces rich user interface components.
2) Application developers who write the model objects and event handlers.
3) Component developers who will create custom components based on the JSF components.
4) Tools vendors who will provide tools that incorporate JSF technology into a new generation of tools that simplify the development of multi tier web-based applications.
5) Application Server vendors who provide a runtime environment that incorporates JSF technology into a new generation of Application Servers that can deploy multi tier web-based applications that use JSF technology.

5) Integrated Ajax support
You can use jQuery, Dojo, or Ext-JS with servlets and JSP. However, JSF lets you use Ajax without explicit JavaScript programming and with very simple tags. Also, the Ajax calls know about the server-side business logic.

6) Form field conversion and validation
JSF has builtin capabilities for checking that form values are in the required format and for converting from strings to various other data types. If values are missing or in an improper format, the form can be automatically redisplayed with error messages and with the previously entered values maintained.

7) Centralized file-based configuration
Rather then hard-coding information into Java programs, many JSF values are represented in XML or property files. This loose coupling means that many changes can be made without modifying or recompiling Java code, and that wholesale changes can be made by editing a single file. This approach also lets Java and Web developers focus on their specific tasks without needing to know about the overall system layout.

This technology also opens up the market for reusable web user interface components. Developers and vendors can use JSF as the building blocks for developing custom faces.

Disadvantages of JSF

1) Bigger learning curve
To use MVC with the standard RequestDispatcher, you need to be comfortable with the standard JSP and servlet APIs. To use MVC with JSF, you have to be comfortable with the servlet API and a large and elaborate framework that is almost equal in size to the core system.

2) Similarly, if you have an existing app and want to add in some small amounts of Ajax functionality, it is moderately easy with jQuery (quite easy if you know JavaScript already). Switching your app to JSF 2.0 is a big investment.

3) Less transparent
With JSF applications, there is a lot more going on behind the scenes than with normal Java-based Web applications. As a result, JSF applications are:
1) Harder to understand
2) Harder to benchmark and optimize

4) Undeveloped tool support
There are many IDEs with strong support for standard servlet and JSP technology. JSF 2.0 is pretty new, and IDE support is weak as of 5/2010.

5) Much weaker automatic validation
Struts comes with validators for email address, credit card numbers, regular expressions, and more. JSF only comes with validators for missing values, length of input, and numbers in a given range.
You can use the Struts/Commons validation library with JSF, but still not as powerful as Struts.

6) Lack of client-side validation
Struts supports JavaScript-based form-field validation; JSF does not.

No comments: