Java
  Home arrow Java arrow Page 3 - Introducing JavaServer Faces
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Introducing JavaServer Faces
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2005-10-06

    Table of Contents:
  • Introducing JavaServer Faces
  • How Does JSF Compare to Traditional Technologies?
  • More Modular User Interface Code
  • Where Does JSF Fit in the Big Picture?
  • What You Need to Get Started

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Introducing JavaServer Faces - More Modular User Interface Code


    (Page 3 of 5 )

    The web application architecture most experienced developers recommend is loosely based on the Model-View-Controller (MVC) design pattern. MVC was first described by Xerox in a number of papers published in the late 1980s, in conjunction with the Smalltalk language. This model has since been used for GUI applications developed in all popular programming languages. The basic idea is to separate the application data and business logic, the presentation of the data, and the interaction with the data into distinct entities labeled the Model, the View, and the Controller, respectively.

    The Model represents pure business data and the rules for how to use this data; it knows nothing about how the data is displayed or the user interface controls used to modify the data. The View, on the other hand, knows all about the user interface details. It also knows about the public Model interface for reading its data, so that it can render it correctly, and it knows about the Controller interface, so it can ask the Controller to modify the Model. Using the MVC design pattern results in a flexible application in which multiple presentations (Views) can be provided and easily modified, and changes in the business rules or physical representation of the data (the Model) can be made without touching any of the user interface code.

    While Java web application frameworks like Struts support the MVC model on a high level, its not supported in the same strict, fine-granular way as in a GUI framework. For example, in Struts, the View is represented by a set of JSP pages, the Controller by a Struts servlet that delegates the real work to Action classes, and the Model by application classes that typically interact with a database or some other permanent storage. The interfaces between the different pieces, however, are not defined as a set of specific methods with declared parameters. Instead, control is passed between the pieces using generic methods, and the data the next piece needs is made available through coarse-grained collections--such as collections of all HTTP request parameters, headers, attributes, and so on. Another major difference between a GUI framework and a typical web application framework is that the latter only recognizes one type of event: the HTTP request. The code that handles this coarse-grained event has to dig through the request data to tell if the user has entered new data in any fields, asked for a different type of presentation by selecting an option in a menu, ordered a transaction to be completed, or something else. A GUI framework, on the other hand, is based on fine-granular events, such as "value changed," " menu item selected," and "button clicked," with separate event handlers dealing with each event.

    The JSF MVC design is similar to Swing and other GUI frameworks, as shown in Figure 1-2.

    Figure 1-2.  JTheJSF MVC design

    The Model is represented by properties of application objects, e.g., ausernameproperty on an application object holding user information. JSF UI components declare what events they can fire, such as "value changed" and "button clicked" events, and external event listeners (representing the Controller) attached to the components handle these events. An event listener may set properties of the JSF components--for instance, adjust the set of rows shown in a table--or invoke backend code that processes the submitted data (say, verify that a credit card is valid or update a database). A separate renderer class (representing the View) renders each JSF UI component, making it possible to render instances of the same component type in different ways (e.g., either as a button or a link, or using different markup languages) just by attaching different renderers.

    Besides the UI components, JSF also defines artifacts like validators and converters, each with a well-defined purpose. The end result is a very modular user interface code model that is easy to maintain, familiar to GUI application developers, and lends itself well to tools support.

    More Java Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "JavaServer Faces", published by O'Reilly....
     

    Buy this book now. This article is excerpted from chapter one of the book JavaServer Faces, written by Hans Bergsten (O'Reilly, 2004; ISBN: 0596005393). Check it out at your favorite bookstore today. Buy this book now.

    JAVA ARTICLES

    - Deploying Multiple Java Applets as One
    - Deploying Java Applets
    - Understanding Deployment Frameworks
    - Database Programming in Java Using JDBC
    - Extension Interfaces and SAX
    - Entities, Handlers and SAX
    - Advanced SAX
    - Conversions and Java Print Streams
    - Formatters and Java Print Streams
    - Java Print Streams
    - Wildcards, Arrays, and Generics in Java
    - Wildcards and Generic Methods in Java
    - Finishing the Project: Java Web Development ...
    - Generics and Limitations in Java
    - Getting Started with Java Web Development in...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT