gamelan
Search EarthWeb
CodeGuru | Gamelan | Jars | Wireless | Discussions
Navigate developer.com
Architecture & Design  
Database  
Java
Languages & Tools
Microsoft & .NET
Open Source  
Project Management  
Security  
Techniques  
Voice  
Web Services  
Wireless/Mobile
XML  
Technology Jobs  

   Developer.com Webcasts:
  The Impact of Coding Standards and Code Reviews

  Project Management for the Developer

  Defining Your Own Software Development Methodology

  more Webcasts...




See the Winners!


Developer Jobs

Be a Commerce Partner
Memory
Data Center Solutions
Rackmount LCD Monitor
Web Design
Baby Photo Contest
Computer Deals
Shop Online
Hurricane Shutters
KVM Switch over IP
Best Price
Holiday Gift Ideas
Domain registration
Boat Donations
KVM over IP

  Quality, Affordable Dental Plans from DentalPlans.com


Download these IBM resources today!
e-Kit: IBM Rational Systems Development Solution
With systems teams under so much pressure to develop products faster, reduce production costs, and react to changing business needs quickly, communication and collaboration seem to get lost. Now, theres a way to improve product quality and communication.

Webcast: Asset Reuse Strategies for Success--Innovate Don't Duplicate!
Searching for, identifying, updating, using and deploying software assets can be a difficult challenge.

eKit: Rational Build Forge Express
Access valuable resources to help you increase staff productivity, compress development cycles and deliver better software, fast.

Download: IBM Data Studio v1.1
Effectively design, develop, deploy and manage your data, databases, and database applications throughout the data management life.

eKit: Rational Asset Manager
Learn how to do more with your reusable assets, learn how Rational Asset Manager tracks and audits your assets in order to utilize them for reuse.
Developer News -
SaaS Tool Offers Custom Database Development    May 9, 2008
Microsoft’s Automated Agent: Can We Talk?    May 7, 2008
Borland Finally Sells CodeGear    May 7, 2008
Red Hat Heads For The JON 2.0    May 7, 2008
Free Tech Newsletter -

Project Management Guide: Developing a Web Site. Best Practices, Tips and Strategies. Download Exclusive eBook Now.

The First Time Ever I Saw Your Face: Getting Started with JavaServer Faces
By David Thurmond

Go to page: 1  2  3  4  5  6  7  8  Next  

Over the years, there have been many frameworks for developing Web-based applications. First came servlets and JSP, but these technologies left a lot of work for developers to build from the ground up each time they built an application.

Apache Struts attempted to address this problem by providing lots of out-of-the-box functionality that could be easily configured, including page navigation, internationalization, and predefined hooks for connecting business logic to the user interface. Although this gave developers a leg up on raw servlets or JSP development, there was still room for improvement.

Now, JavaServer Faces improves on Struts by providing even more pre-built, reusable functionality to developers, including improved navigation functionality, internationalization support, forms input validation, data conversion, and perhaps most powerful of all, a true model-view-controller design for creating web-based applications. Here, I will explore the many features of JSF by developing a small application that takes advantage of what this framework has to offer.

What Is JSF?

JSF is a community-based development effort to bring true model-view-controller design to web-based applications. This new framework provides standard, reusable components for building a web page, built-in support for internationalization, built-in hooks for forms input validation and data conversion, and a standard method for linking client-side events to server-side application processing.

According to the Java Community Process site for JSF, which can be found at http://www.jcp.org/en/jsr/detail?id=127, the goals of JSF are as follows:

  • Create a standard GUI component framework which can be leveraged by development tools to make it easier for tool users to both create high quality GUIs and manage the GUI's connections to application behavior.
  • Define a set of simple lightweight Java base classes for GUI components, component state, and input events. These classes will address GUI lifecycle issues, notably managing a component's persistent state for the lifetime of its page.
  • Provide a set of common GUI components, including the standard HTML form input elements. These components will be derived from the simple set of base classes that can be used to define new components.
  • Provide a JavaBeans model for dispatching events from client-side GUI controls to server-side application behavior.
  • Define APIs for input validation, including support for client-side validation.
  • Specify a model for internationalization and localization of the GUI.
  • Automatic generation of appropriate output for the target client, taking into account all available client configuration data, such as browser version, and so forth.
  • Automatic Generation of output containing required hooks for supporting accessibility, as defined by WAI.

In a nutshell, JSF provides everything you need to render a client-appropriate UI to the user, get and validate the user's input, and connect the UI to the server-side processes that make up the application.

Tools of the Trade

To get started writing a JSF application, you will need to download an implementation of the JSF specification. An easy way to get one is to grab a copy of Sun's J2EE 1.4 application server. This server can be downloaded at http://java.sun.com/j2ee/1.4/download.html. You also can download the Apache MyFaces implementation at http://myfaces.apache.org/ and install it on your own particular application server instance.

The Hangman Application

Now, it's time to get started with JSF!

The application you'll develop is a word game called Hangman. In this game, a player is presented with a word puzzle, shown as blanks to be filled in. The player guesses a letter, and if it is correct, the letter is shown in the puzzle.

Each time the player guesses incorrectly, a message indicates that the letter is not in the puzzle. If the player guesses too many times, the game ends, the answer to the puzzle is revealed, and the player has a chance to play again.

The player can try to solve the puzzle any time during the game. If the player guesses the puzzle correctly, he wins, and has a chance to play a new game. If the guess is incorrect, it does not count against the number of guesses used.

The steps for developing any JSF application are:

  1. Develop the application pages using JSF components.
  2. Define page navigation in the jsf-config.xml file.
  3. Develop the Java beans for the business logic.
  4. Add forms validation to the application.

In the following sections, I'll tell you about various important points about each of these steps. When you're done, you'll have a fully functioning word game.

The faces-config.xml File

Before you jump into developing the application, you must create a faces-config.xml file. Every JSF application must have a faces-config.xml file in which security policies, business logic bean definitions, validation classes, conversion classes, and navigation rules for the application are defined. This file must be present in the WEB-INF directory of the application, along with web.xml, to begin development. I'll show you all of the parts of this file in detail later. A complete listing of the faces-config.xml file is available here.

Creating the User Interface

The application needs pages to perform the following functions:

  1. newGame.jsp: The first page of the application. This page will allow the player to enter his name, choose a difficulty level, and start the game.
  2. showPuzzle.jsp: This page is where the puzzle is shown and the player has a chance to guess a letter or solve the puzzle. If the player correctly guesses a letter, it is shown in the puzzle. If not, a message will tell the user that the letter was not in the puzzle, or that the letter was already guessed.
  3. youWin.jsp: On this page, the player receives a congratulatory message for solving the puzzle, and a link is shown to get back to the new game page.
  4. youLose.jsp: On this page, the answer to the puzzle is shown, and a link is shown to get back to the new game page.
  5. index.jsp: This page is the default page that comes up whenever a player visits the default application URL, http://localhost:8080/hangman/. It will automatically forward the player to the newGame.jsp page.

To develop the JSP pages that make up the application, you'll use the standard components that are available in JavaServer Faces. These are analogous to the normal HTML tags for form rendering and user input.

Go to page: 1  2  3  4  5  6  7  8  Next  


Tools:
Add www.developer.com to your favorites
Add www.developer.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed


Enterprise Java Archives

Work With InterSystems. Not Separate Systems. Rapidly develop and deploy connectable applications.
Developing Intelligent Communications? Visit the Avaya DevConnect Center on DevX.
Flash Demo: Learn how IBM Information Server Blade is easy to manage, highly scalable and efficient.
Best Practices for Developing a Web Site. Checklists, Tips & Strategies. Download Exclusive eBook Now.
Whitepaper: XML Processing in Applications--Take the Next Step



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES