Spring Book – Chapter 13 – Spring and JSF Integration

JavaServer Faces Libraries

JavaServer Faces is a standardized specification for building User Interfaces for server-side applications. There are two main JSF implementations, both open -source namely:

  • Sun Mojarra – reference implementation provided by Oracle. Jars include jsf-api.jar and jsf-impl.jar.
  • Apache MyFaces – Jars include myfaces-api.jar and myfaces-impl.jar.
  • Any other Java EE 6 server, as JSF 2.0 has become an official part of Java EE 6 platform. examples of supported Java EE 6 servers being JBoss 6, Weblogic 11g, WebSphere 8, tec.

Like any other specification, JSF has gone through various iterations in the form of versions starting with version 1.0 all the way up to version 2.1 at the time of writing this book. There have been many releases of version 1.1 and 1.2 at various stages more concentrated on bug fixing.

There are many component libraries in market for JSF. Some of them are as summarized below:

  • JBoss RichFaces
  • ICEfaces
  • PrimeFaces
  • Oracle ADF Faces

Configuring JSF

Configuring JSF application is as simple following the steps as described below in bulleted format for better reading:

  • Include the JSF implementation libraries in your web application
  • Configure the FacesServlet provided by the JSF implementation. It acts as the FronController servlet for your JSF application and is typically mapped by extensions similar to *.faces etc. This servlet is responsible for driving the JSF lifecycle as a whole.
  • Rest or almost all of the configurations is done through the use of faces-config.xml file. This configuration file was quite verbose in JSF version 1.2 but JSF version 2.x brought in lot of implications using Java annotation.

Why JavaServer Faces?

You might be asking the question, so why JSF? There are so many web frameworks available in market and some are really good but with lack of marketing. Why should we go with developing web application based on JSF? The answer to this question can be summarized below by giving the benefits which JSF technology provides:

  • Built on standard JSF specification. Huge vendor and industry support. This means that you can expect good level of support and quality components from these vendors.
  • Makes it easy for developers to use. Yes, very opinionated, I know. But I am sure most of the readers would be with me in saying that, user interfaces can be easily created with JSF using in-built component library by handling complexities in user interface management. This will surely bring in improved productivity and consistency. JavaScript code is embedded as part of the component making it easy for developers and provides more code reusability on JavaScript code.
  • JSF brings in clean separation between behavior and presentation which inherently brings simplicity in design. This will intern bring in clean separation between various roles in an organization.
  • Provides rich and concrete architecture for managing component state, processing data, validating input and handling events. The concept of validator and converters are really helpful and useful.
  • Very robust event handling mechanism similar to thick client applications which have is important in any modern day web application having rich look and feel.
  • Support of different client rendering by the use of different render kits.
  • Key factor that JSF is highly pluggable in nature supporting plugging in third-party components, view handlers etc. making it really extensible in nature.
  • JSF has very good support for expression language (EL) support which will improves the user interface code readability to a greater extent.

Disadvantages of JSF

Having said some rosy picture about JSF, let’s now delve into not so rosy picture about JSF. They can be summarized briefly as shown below:

  • There are so many third-party component libraries but they don’t generally work together. Simply put they don’t mix in an application.
  • Customizing a component provided by the component library can be quite a task in itself.
  • Heavy usage of HTTP session can put lot of strain on the server resources and as the application grows can be potentially threatening to some extent. High performance application can suffer because of high footprint of server resources.
  • Some very common web requirements like URL design, bookmarking etc. can be harder to implement and put more work on the developers implementing these requirements.
  • Applications requiring dynamic component rendering like adding and removing component based on business case can be hard to implement.
  • Default error messages are not so good.
  • Comparatively with respect to other web frameworks, learning curve is higher. Not so helpful and good documentation makes it more stressful to developers.
  • Compared other frameworks, there are so much going on behind the scenes making it harder for developers to debug and drill to the root cause.

I haven’t covered nitty-gritties of each component and its flaws as it can be quite cumbersome to understand at this point in time. But there exists specific disadvantages associated with certain component implementation which can make developers unhappy.

JSF vs. Struts

JSF has more advantages compared to programming web application using JSP along with Servlets and Struts. But it’s worthwhile knowing that Struts and JSF can co-exists in a well application. Compared to JSF, Struts has following disadvantages as summarized below:

  • Struts don’t have built-in event model for UI components.
  • Struts don’t have built-in UI component model.
  • Struts don’t have built-in state management for UI components.
  • Struts don’t have built-in support for multiple renderers. Struts is limited to HTML and HTTP.
  • Above all, Struts is not a standard. Vendor and tool support less as compared to JSF.

JSF 2.x

JSF 2.0 is the first major revision since the original standard designed way back in 2004. Standard was completed in summer 2009 and implementation from Sun Mojarra released in October 2009 and Apache MyFaces in April 2010. Major improvement brought in many areas, some of well know ones can be summarized as shown below:

  • Ajax has become a standard way of doing things.
  • Rendering capability using Facelets and it has been built into the standard.
  • New State using view/flash scopes.
  • Configuration support using annotations bringing in simplicity and configuration ease.
  • JSR-303 validation support
  • Support for GET and bookmarkability.
  • Navigations based on conventions.

Page Visitors: 3640

The following two tabs change content below.
Tomcy John

Tomcy John

Blogger & Author at javacodebook
He is an Enterprise Java Specialist holding a degree in Engineering (B-Tech) with over 10 years of experience in several industries. He's currently working as Principal Architect at Emirates Group IT since 2005. Prior to this he has worked with Oracle Corporation and Ernst & Young. His main specialization is on various web technologies and acts as chief mentor and Architect to facilitate incorporating Spring as Corporate Standard in the organization.
Tomcy John

Latest posts by Tomcy John (see all)

1 thought on “Spring Book – Chapter 13 – Spring and JSF Integration

  1. Hey very cool blog!! Man .. Excellent .. Wonderful .. I will bookmark your blog and take the feeds also?I’m happy to find a lot of helpful info right here in the put up, we need develop extra techniques in this regard, thank you for sharing. . . . . .

Leave a Reply

Your email address will not be published. Required fields are marked *