JSF 2.0: Introduction and Overview

15

JavaServer Faces (JSF) is a Java-based Web application framework intended to simplify development integration of web-based user interfaces.

JSF is a request-driven MVC web framework based on component driven UI design model, using XML files called view templates or Facelets views. Requests are processed by the FacesServlet, which loads the appropriate view template, builds a component tree, processes events, and renders the response (typically HTML) to the client. The state of UI components (and some other objects) is saved at the end of each request (called stateSaving (note: transient true)), and restored upon next creation of that view. Several types of state-saving are available, including Client-side and Server-side state saving. Out of the box, JSF 1.x uses JavaServer Pages (JSP) for its display technology, but can also accommodate other technologies (such as XUL and Facelets). JSF 2 uses Facelets by default for this purpose. Facelets is a more efficient, simple, and yet more powerful view description language (VDL).

New Features

  • View Declaration Language with Facelets – Templating support
    • Easy creation of custom components
  • Ajax
  • State Saving
    • Separate the “build the tree” and “render the tree” processes into two separate lifecycle phases.
    • Allow for partial tree traversel during lifecycle execution via Ajax.
    • Performance
  • New scopes
    • Flash Scope
    • View Scope
  • No configuration needed – Magic of Annotations
    • Managed Bean Annotations
    • Component Annotations
  • Improved Validation
    • Validationgroups
  • Implicit Navigation
  • Strategic additions to the Standard HTML RenderKit: Date Picker, Tree, Tab View, File Upload components.
  • Provide a mechanism to minimize the “Lost Update” and “Duplicate Button Press” problems. These mechanisms must be pluggable or customizable from the user.

JSF vs. Servlets/JSP

The MVC Architecture

  • Bad JSP design

Many books or articles on Java-based Web frameworks start with this example:


<h1>Tiny bit of HTML</h1>

<% Java

Java

Java

More Java %>

<h1>Tiny bit of HTML</h1>

Then, they redo the example using the framework and comment on how much better it is.

  • This proves nothing
  • MVC

A fair comparison is to look at the use of the framework vs. the use of MVC with servlets and JSP

A Quick Review of MVC

Advantages of JSF

vs. MVC Using RequestDispatcher

  • Custom GUI controls

JSF provides a set of APIs and associated custom tags to create HTML forms that have complex interfaces

  • There are many extra-rich third-party JSF libraries
  • Event handling

JSF makes it easy to designate Java code that is invoked when forms are submitted. The code can respond to particular buttons, changes in particular values, certain user selections, and so on.

  • Managed beans

In JSP, you can use property=”*” with jsp:setProperty to automatically populate a bean based on request parameters. JSF extends this capability and adds in several utilities, all of which serve to greatly simplify request param processing.

  • 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.

vs. Standard MVC

  • 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.

  • Centralized file-based configuration

Rather than 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.

  • Consistent approach

JSF encourages consistent use of MVC throughout your application.

Disadvantages of JSF

vs. MVC with RequestDispatcher

  • 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.
    • 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.
  • Worse documentation

Compared to the standard servlet and JSP APIs, JSF has fewer online resources, and many first-time users find the online JSF documentation confusing and poorly organized. True for both Mojarra and MyFaces

vs. Standard MVC

  • 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:

  • Harder to understand
  • Harder to benchmark and optimize
  • 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.

  • Rigid approach

The flip side of the benefit that JSF encourages a consistent approach to MVC is that JSF makes it difficult to use other approaches.

15 Responses

  1. Iyana Other says:

    The second part will include an overview of the study tasks for the project. Iyana Other

  2. See our Software for Kazakh Language Learning Reading this introduction to Yiddish will help you get an overview of the language you are learning. Custom Wholesale

  3. See our Software for Bengali Language Learning Read our introduction to Farsi if you want an overview of the language you’re learning. Files Protectors

  4. See our Software for Azerbaijani Language Learning If you want an overview of the language that you are learning, read our introduction to Kazakh. Early Learning Wholesale

  5. Yoj says:

    where is the jsf 2.0 introduction and overview ?

  6. Yoj says:

    where is the jsf 2.0 introduction and overview ?

  7. See our Software for Kazakh Language Learning Reading this introduction to Yiddish will help you get an overview of the language you are learning. Alena Strings

  8. I randomly browse blogs on the internet, and I discover your article to be very informational. I have already bookmark it on my browser, so that I can view your blog submit again later. Also, I’m wondering whether or not your weblog is open for hyperlink alternate, as I really need to trade links with you. I do not usually do this, but I hope that we can have a mutual hyperlink exchange. Let me know and have a great day!

  9. looks very interesting for me.

  10. vertu says:

    Hello webmaster I like your post ….

  11. Is it me or did this article make you want to buy an iPad?

  12. Violet Nang says:

    Baby bears, called cubs, are born in a den

  13. See our Software for Azerbaijani Language Learning If you want an overview of the language that you are learning, read our introduction to Kazakh. File Conversion Wholesale

Leave a Reply

© 2010 Developer Articles. All rights reserved.
Powered by: Aaban Technologies