Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Building Applications with IBM Rational Application Developer and JavaBeans
Building Applications with IBM Rational Application Developer and JavaBeans
Building Applications with IBM Rational Application Developer and JavaBeans
Ebook862 pages6 hours

Building Applications with IBM Rational Application Developer and JavaBeans

Rating: 0 out of 5 stars

()

Read preview

About this ebook

Designed for programmers with limited Java experience, this informative guidebook shows how applications, applets, and servlets can be created with ease using IBM's Rational Application Developer paired with JavaBeans. Step-by-step guidelines accompanied by screen captures and code samples demonstrate how to build JavaServer Faces Web applications, as well as Java applications complete with graphical user interfaces. Instruction is also provided on using Rational Application Developer's debugger, incorporating relational databases with Java, and adding Asynchronous JavaScript and XML behavior to applications in order to produce more interactive and usable web pages. Exercises at the end of each chapter ensure that even novice Java programmers will learn how to combine reusable components to get applications up and running quickly.

LanguageEnglish
Release dateFeb 16, 2016
ISBN9781931182447
Building Applications with IBM Rational Application Developer and JavaBeans

Related to Building Applications with IBM Rational Application Developer and JavaBeans

Related ebooks

Programming For You

View More

Related articles

Reviews for Building Applications with IBM Rational Application Developer and JavaBeans

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Building Applications with IBM Rational Application Developer and JavaBeans - Colette Burrus

    The authors and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein.

    © Copyright 2008 by International Business Machines Corporation. All Rights Reserved

    Note to U.S. Government Users: Documentation related to restricted right. Use, duplication, or disclosure is subject to restrictions set forth in GSA ADP Schedule Contract with IBM Corporation.

    IBM Press Program Manager: Tara B. Woodman, Ellice Uffer

    Cover Design: IBM Corporation

    Published by MC Press Online, LP

    Publishing as IBM Press

    Building Applications with IBM Rational Application Developer and JavaBeans

    A Guided Tour

    Colette Burrus and Stephanie Parkin

    IBM Press offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests. For more information, please contact:

    MC Press

    Corporate Offices:

    125 N. Woodland Trail

    Lewisville, TX 75077

    817.961.0660

    The following terms are trademarks or registered trademarks of International Business Machines Corporation in the United States, other countries, or both: IBM, the IBM logo, IBM Press, AIX, DB2, developerWorks, Informix, Rational, and WebSphere. Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both. Microsoft, Windows, Windows NT, and the Windows logo are trademarks of Microsoft Corporation in the United States, other countries, or both. UNIX is a registered trademark of The Open Group in the United States and other countries. Linux is a registered trademark of Linus Torvalds in the United States, other countries, or both. Other company, product, or service names may be trademarks or service marks of others.

    All rights reserved. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, write to:

    MC Press Online, LP

    Sales and Customer Service

    P.O. Box 4300

    Big Sandy, TX 75755-4300

    www.mcpressonline.com/ibmpress

    ISBN: 978-1-931182-27-0

    Printed in Canada, at WebCom Ltd, Toronto, Ontario.

    First printing: February, 2008

    Acknowledgments

    We are now in the third edition of this book, which started life in 1998 as a series of tutorials originally created by a talented group at Software House Technology in Riga, Latvia. Under the leadership of Dave Pullen, the writing team included Tatjana Lukovnikova, Pavels Nikolajevs, Juris Krikis, and Tatjana Apine, in addition to us. And thanks to the many developers who worked on the JavaBeans Around the World project, which provided the core technology for some of the samples in this book.

    We’d like to thank the many people at IBM who helped with the development of this book. A big thanks to our primary technical reviewers across the pond: Dave Artus and Jonathan Marshall, for taking time out of their busy schedules to review many chapters. Also thanks to Sheila Sholars, Becky Nin, Mark Hager, Yuri Kats, and Tom Mutdosch for lending us their product expertise. Thanks also to Katie Kean for her sponsorship, and to Jim Mann and Susan Croce, who have enthusiastically supported us through several iterations of this work.

    We’d also like to thank the Rational team for getting us early access to product drivers, in particular Nick Teshima, Galina Bernshteyn, and Matthew Gammie. And finally, a warm thanks to Merrikay Lee and Tara Woodman for their patience and expertise with the publishing process.

    Contents

    About this book

    Introduction

    Chapter 1: Creating your first JavaServer Faces Web application

    Introducing Web Applications and JavaServer Faces

    Installing Rational Application Developer

    Setting up a Web Project

    Creating the Web Application

    Running the Web Application

    In Review

    Exercise

    References

    Chapter 2: Using Web diagrams

    Setting Up the Web Project

    Creating the Web Diagram

    Updating the Web Pages

    Running the Web Application

    In Review

    Exercise

    Chapter 3: Using custom converters and validators

    The JSF Life Cycle

    Setting Up the Web Project

    Creating the Web Page

    Using a Custom Converter

    Using a Custom Validator

    Creating the Action Listeners

    Running the Web Application

    Running the Web Application in Debug Mode

    In Review

    Exercise

    References

    Chapter 4: Working with databases

    Introduction to Relational Databases

    Creating the Database

    Creating the Data Model

    Deploying the Model

    Working with Table Rows

    In Review

    References

    Chapter 5: Using Relational Record components

    Creating the Friends Web Page

    Updating Friend Information

    Adding New Friends

    Running the Web Application

    In Review

    Exercise

    Chapter 6: Using panel components

    Using a Form Box

    Using Menu and Action Bars

    Using a Section Panel

    In Review

    Exercise

    Chapter 7: Using Ajax with Faces Web pages

    Creating the Calculator Web Page

    Adding Ajax Behavior to the Web Page

    Creating the RestaurantSearch Web Application

    Adding Ajax Behavior to the Web Application

    Using the Ajax Type-ahead Feature

    In Review

    Exercise

    References

    Chapter 8: Creating your first applet

    Setting Up the Java Project

    Your First Applet

    Limiting the Number of Entries

    Sorting the List

    Publishing Your Applet

    In Review

    Exercise

    References

    Chapter 9: Creating your first application

    Updating Your Project

    Your First Application

    Adding Functionality to Your Application

    Working with Files

    Publishing Your Application

    In Review

    Exercise

    References

    Chapter 10: Creating a file-manipulation subcomponent

    Creating a Subcomponent

    Adding File Dialogs

    Promoting Bean Features

    Adding the Bean to the ToDoList Application

    In Review

    Exercise

    Chapter 11: Using layout managers

    BorderLayout Manager

    FlowLayout Manager

    Creating a Subcomponent with Radio Buttons

    CardLayout Manager

    GridLayout Manager

    BoxLayout Manager

    GridBagLayout Manager

    In Review

    Exercise

    Chapter 12: Using Swing components

    Java Foundation Classes and Swing

    Creating a Swing Application

    Completing the SwingToDoList Application

    Using Swing’s Model-View-Controller Design

    Connecting Beans in the TimeModelDemo Application

    Using JSlider and JProgressBar

    Swing Applets

    Changing the Look and Feel

    In Review

    Exercise

    References

    Chapter 13: When something goes wrong: Debugging

    ImageProcessing: Menu Bar

    ImageProcessing: Functionality

    Debugging Events

    Debugging Logic Errors

    In Review

    Exercise

    References

    Chapter 14: Using DB beans for database access

    Creating the MyFriends Database Application

    Using the DBSelect Bean

    Completing the Application

    In Review

    Exercises

    Chapter 15: Working with XML data

    Introduction to XML

    Creating the XML Schema and XML File

    Setting Up the JavaBeans for the XML File

    Creating the MyBooks Application

    In Review

    Until We Meet Again

    Appendix Java basics

    Object-oriented Terminology

    What a Java Program Looks Like

    In Review

    References

    About this book

    This book is organized as a series of hands-on tutorials. Each chapter of this book contains a tutorial teaching a particular visual programming topic using Rational Application Developer and JavaBeans. The book consists of two parts. The first part (Chapters 1–7) shows you how to visually create JavaServer Faces Web applications using the Page Designer tool. The second part (Chapters 8–15) shows you how to visually create Java applets, applications, and subcomponents using the Visual Editor for Java. In each chapter you’ll create and test at least one new running program.

    Part 1. Creating JavaServer Faces Web Applications

    Chapter 1. Creating your first JavaServer Faces Web application: Introduces you to Rational Application Developer, JavaServer Faces (called JSF or Faces) and the Page Designer tool. It also shows how to build a simple Faces Web application, using basic Faces UI components, validation, event handling, and navigation from one Web page to another.

    Chapter 2. Using Web diagrams: Shows how to organize the design for a Faces Web application using the Web diagram editor, and how to launch Page Designer from the editor to create Faces Web pages. The sample application for this chapter also shows how to use more complex Faces UI components (such as data grids), and how to use Faces managed beans to save session data across multiple Web pages.

    Chapter 3. Using custom converters and validators: Shows how to use custom converters and validators to perform application-specific conversion and validation of Faces UI components. It also shows how to run Faces Web applications in debug mode.

    Chapter 4. Working with databases: Shows how to use the Data perspective in Rational Application Developer to create and work with a relational database table. You’ll create a Friends database that lets you store information about your friends, including digital photos. In later chapters you’ll create a Faces Web application and a Java application that let you create, read, update, and delete information in the Friends database.

    Chapter 5. Using Relational Record components: Shows how to create a Faces Web application that accesses your database table by using Relational Record and Relational Record List components.

    Chapter 6. Using panel components: Shows how to create Faces Web applications that use some of the advanced panel components that Rational Application Developer provides, including form boxes, menu bars, action bars, and section panels.

    Chapter 7. Using Ajax with Faces Web pages: Shows how to add Asynchronous JavaScript and XML (Ajax) behavior to Faces Web applications to improve the application’s usability and responsiveness.

    Part 2. Creating Java Applets, Applications, and Subcomponents

    Chapter 8. Creating your first applet: Introduces you to the Visual Editor for Java and teaches you how to build your first applet, a simple ToDoList program. It also teaches how to publish your applet to run it in a Web browser.

    Chapter 9. Creating your first application: Shows how to build the ToDoList program as a Java application with the capability to save the list to a file so you don’t lose your data each time you close the program.

    Chapter 10. Creating a file-manipulation subcomponent: Teaches how to create a subcomponent (a.k.a. JavaBean) that extends your ToDoList application by adding a reusable FileManipulationPanel component. You will add standard file dialog windows for loading and saving files and hide all the complex wiring inside your own visual bean.

    Chapter 11. Using layout managers: Gives an overview of the layout managers that the Java platform provides, rules for using them, and some examples of usage. Layout managers let you align, space, and size objects that make up your user interface.

    Chapter 12. Using Swing components: Teaches how to use components of the Swing class library, which provides a customizable look and feel for your applications. These components also provide built-in functions, such as icons, rollover buttons, and help text.

    Chapter 13. When something goes wrong: Debugging: Teaches how to debug problems in your applications using the Rational Application Developer Debug perspective. We’ll create a buggy application and then walk you through the steps of finding and correcting the problems.

    Chapter 14. Using DB beans for database access: Teaches how to build a Java application for accessing your database table, using the DB beans for database access.

    Chapter 15. Working with XML data: Introduces XML concepts and shows how to create an XML Schema, generate JavaBeans from the XML Schema, and create a Java application for working with XML data, using the generated JavaBeans.

    Appendix. Java basics: Provides a quick primer for the Java programming language. If you’re new to Java, read this appendix before diving into the rest of the book.

    Conventions

    In each chapter of this book you’ll create at least one complete Faces Web application, Java applet, or Java application. Each chapter provides certain key elements:

    Time required: Tells you approximately how long each lesson should take to complete. Lessons generally take two hours.

    Files required: Tells you which files you need from the CD-ROM to complete the lesson. We’ve provided source files and components you’ll need in each chapter, plus solution files showing the end result of each exercise. If you ever get lost, you can check the solution file to get you back on track. All of the required files are in the solutions subdirectory of the CD-ROM provided with this book.

    Screen captures: Show you how to complete each step of the lesson.

    Text conventions: We’ve tried to use the same text conventions as the Rational Application Developer documentation. For example, interface elements that you select appear in boldface. Code samples appear in monospace font.

    Terminology definitions: Appear at their first usage in the chapters. If you want to look up a particular term, check the index.

    Sidebar text: Explains certain key concepts or terms that relate to the lesson on that page. Text appears in sidebars when we don’t want to interrupt the flow of detailed instructions.

    Introduction

    This book takes you on a guided tour to visually building applications with Rational Application Developer and JavaBeans. Along the way, you’ll learn the basics of how to develop JavaServer™ Faces Web applications, Java™ applets, and Java applications, as well as more advanced topics such as using relational databases and eXtensible Markup Language (XML) documents to store your application data. By the end of the tour you’ll be able to use Rational Application Developer to build your own applications, and you’ll understand why JavaBeans are so useful for application programming.

    If you’re new to Java and Java development environments, that’s OK. This book assumes you have some basic knowledge of the Java programming language, but you certainly don’t need to be an expert to follow the tour. You do need to be running one of the Windows® operating systems, but as long as you’re comfortable with Windows, the Internet, and Web browsers, you’re ready to learn Java.

    If you are already familiar with Java and Java development environments, that’s OK too. You’ll still benefit from going through the tour, because it will teach you many of the Rational Application Developer features that let you build your applications easier and faster.

    This book uses the show-and-tell approach. If you flip through the pages, you’ll notice they are loaded with pictures showing how your applications should look at each step along the way. In addition, we’ve included a CD-ROM containing all the source files and components you’ll need to follow along with the lessons.

    Why Java?

    Java is considered the language of the Internet. It combines two important advances in computer science: object orientation and platform independence. Object-oriented means the programming language models real-world components and behavior. You organize your programs into objects with certain properties and define the activities objects can perform. Complex behavior is hidden in the implementation of the object, letting you just connect the object to other objects.

    In addition, Java is platform-independent, meaning you can create programs on a Windows machine and be confident that the program will work in any environment Java runs in.

    In the past few years the use of Java has exploded. It has expanded well beyond its original main purpose of providing dynamic Web pages to become a full server-side programming language. It enables the development of complex Internet functionality, such as querying legacy databases, enabling business-to-business Web commerce, and providing interactive Web communications. Because it’s based on open standards, all Java programs use a common API, meaning you can reuse other Java components and easily snap them into your programs.

    Rational Application Developer

    Rational Application Developer 7.0 is the development tool you’ll use during the guided tour. As you’ll see, Rational Application Developer is a full-function integrated development environment that contains everything you need to create, test, and maintain your JavaServer Faces Web applications, Java applets, and Java applications. The Page Designer and Visual Editor for Java tools you’ll use make development even easier and faster—you just drag and drop the elements you want to use, customize them to set the properties you want, and the tools generate the underlying code for you.

    JavaBeans

    JavaBeans are the Java components you’ll use to build applications during the guided tour. You’ll use the standard user interface elements (visual beans such as buttons and text fields) that come with Rational Application Developer, as well as nonvisual beans to perform complex functions such as sorting data, working with databases, and working with XML documents. As you’ll see, JavaBeans simplify the work of application programming because they provide prebuilt components with simple interfaces you’ll use to customize their functions and wire them into your applications.

    Ready to Learn How?

    This book shows you how easy it is to create applications with Rational Application Developer and JavaBeans. It describes the right components and the right tools and explains how to use them together to create simple yet useful programs.

    As an additional benefit for readers of this book, we’ve established an email contact where you can send your comments and questions about beans and programming with them. We will monitor this ID and answer any questions you send in. Email your questions and comments to: beans@pobox.com.

    Chapter 1

    Creating your first JavaServer Faces Web application

    Chapter Contents

    Introducing Web applications and JavaServer Faces

    Installing Rational Application Developer

    Setting up a Web project

    Creating the Web application

    Running the Web application

    Time Required

    2 hours

    Files Required

    none

    We begin our guided tour by introducing you to Web applications and JavaServer Faces (called JSF or Faces), followed by a simple example of how you can create Faces Web applications in Rational Application Developer. JSF provides a rich set of user interface (UI) components and a solid framework upon which to build Web applications, but as you’ll see in this book, the power really lies in Rational Application Developer’s tooling, which lets you visually build Web applications.

    Introducing Web Applications and JavaServer Faces

    Web applications reside on application servers such as WebSphere® Application Server. These applications consist of one or more Web pages that users access through Web browsers, as shown in Figure 1–1.

    Figure 1–1: User requests from a Web browser

    Web applications typically contain a combination of static and dynamic content, such as text and images, and programs that run on the server or in the user’s Web browser. When a user clicks a link or a button on a Web page, the request is sent to the server, which processes it and returns the response (which could be on the page already loaded or on a new page) to the user’s Web browser. Web pages returned to the Web browser consist of tags, drawn from languages such as Hypertext Markup Language (HTML) or JavaScript™, which the browser interprets into user elements on-screen.

    As far as the user is concerned, what happens on the Web application server to process a request doesn’t really matter so long as it’s done quickly enough. From your perspective, however, what happens on the server—and the steps needed to make it happen, including what needs to be done to develop Web pages, deploy them to servers, and maintain Web applications—matters quite a bit, because it determines how easy your job is.

    One technology frequently used to develop Web applications is a JavaServer Page™ (JSP). A JSP is a dynamic Web page that combines static HTML elements with Java code. The application server compiles and runs the JSP when a user requests the page via a Web browser, and it returns the resulting output to them. Because one of the problems with JSPs is their combination of presentation logic (HTML tags controlling the display of visual elements) with control logic (Java code performing dynamic processing), they can be difficult to maintain for large Web applications.

    Faces Web pages are similar to JavaServer Pages, in that they combine HTML tags with Java code and are compiled and run on servers when users request Web pages. The chief distinction of JSF is that Web developers work with Faces UI components on the Web page—rather than with HTML elements. This technique lets you create Web applications using Model-View-Controller (MVC) architecture, as is typical with client-server applications. The JSF framework acts as the controller managing the steps for processing the Web page, including validating, converting, and acting on data that users enter via the Web page. You define your Web application’s data in an object model, bind the object model to Faces UI components on the Web page (creating viewable elements), and link actions with particular events, such as selection of links or buttons on the Web page.

    Model-View-Controller architecture

    The Model-View-Controller (MVC) architecture is a well-known design pattern for structuring applications. The model contains state data for the application, such as values entered by users. View refers to the appearance of data on-screen, controlling what users see. The controller determines the application’s reactions to events, such as mouse clicks and keyboard input.

    The Faces UI components include common elements, such as input and output fields, check boxes, and buttons; but they also include more complex components, such as table grids that you can bind to a collection of data items or a database table. The components provide many useful built-in features: For example, you can customize components both to verify that users supply data in particular input fields and to automatically convert user data into various formats. JSF is readily extensible; you can build your own components that operate within the JSF framework. Other features let you easily control navigation from one Web page to another by specifying which page the user should be directed to when an action is successful—or which other page when it fails. Each component also includes standard event listeners, such as an action listener for button clicks, that apply the processing logic associated with a particular event.

    You define the object model for your Web application in JavaBeans, called managed beans, which the JSF framework manages automatically, deciding when to create beans, maintaining references to them, and removing references when beans are no longer needed. When a bean property is bound to a particular UI component, JSF automatically displays the property’s current value in the Web page and sets the property with any newer user-entered value. Specifying the scope for a managed bean determines how long the bean will be available. For example, when you set the scope to request, the bean is only available to the current Web page request, but when you set the scope to session, the bean is available to all Web pages in the user’s current session, letting you easily pass data from one Web page to another. Scope also tells the JSF framework what a bean’s lifecycle should be.

    As you’ll see when you build the Faces Web applications in this book, Rational Application Developer handles most of your work for you. For each Faces Web page you create, the Page Designer tool creates a special Java class, called a PageCode class, containing that page’s processing logic. The PageCode class sets up the context for the current request and gives you the appropriate points to insert the logic for your event listeners. You typically won’t edit the PageCode class directly; instead, you’ll use the Page Data view to identify the data objects associated with the Web page (such as the JavaBeans that define the application’s object model), the Page Designer to create the view for your Web page, and the Quick Edit view to create event listeners.

    What’s a class?

    A class is a set, or group, made up of members sharing the same state and behavior. Each Java program is a class, and each class has a superclass defining where the class fits into the object hierarchy. Just as you may have inherited certain traits from your parents, a Java class can inherit both state and behavior from its superclass.

    In the rest of this chapter, we’ll take you step-by-step through developing a simple Faces Web application, introducing some of the basic Faces UI components (text fields, radio buttons, check boxes, buttons, and so on) and familiarizing you with the Page Designer. The Web application you’ll build consists of two Web pages: an HTML input form for a simple survey (shown in Figure 1–2) and a second Web page echoing the values entered in the input form. To pass data from one Web page to the other, you’ll use a managed bean with request scope, binding the Faces UI components of your Web pages to properties in the managed bean.

    Figure 1–2: The Survey application’s input form.

    What’s an HTML form?

    HTML forms collect information entered by users via Web browsers, passing it to Web applications for processing. HTML forms simplify data entry by incorporating text fields, radio buttons, pull-down menus, or other UI elements. When a user clicks the Submit button contained within the form, the user-input values are passed as parameters to an application server program, such as a JSP or JSF servlet. The Web application processes the input and returns a Web page to the user’s Web browser with an appropriate response. You specify the URL for the application server program in the form’s Action attribute. Within the form, you specify the various HTML tags controlling the display of the input fields and Submit button. HTML forms generated from Faces Web pages have elements created as Faces UI components, which the JSF framework converts into the appropriate HTML tags.

    Installing Rational Application Developer

    In order to follow along with the steps in this book, you need to install IBM Rational Application Developer 7.0. If you don’t already have a copy, you can download a free trial version at http://www.ibm.com/developerworks/downloads/r/rad. Follow the installation instructions bundled with the program, first installing the IBM Installation Manager, which you use to install, update, and uninstall product packages as well as manage product licenses. The instructions in this book assume that Rational Application Developer is installed in the default folders for shared resources and package groups.

    After installing Rational Application Developer, make sure you use the IBM Installation Manager to install the latest product updates. You’ll need Rational Application Developer 7.0.0.2 or later to properly use the samples in this book.

    Setting up a Web Project

    Before you can create your first Web application, you need to do some preparatory work in Rational Application Developer to specify where your Web application will be saved.

    Rational Application Developer is organized into a variety of perspectives, or different ways of looking at a development project based on your role on the development team. In this book, you’ll use the Web perspective to build Faces Web applications, and, later, you’ll use the Java perspective to build Java applets and applications. Within the Web perspective, your Web applications are organized into projects and folders according to their content, such as package folders for Java classes. You can switch perspectives whenever you need to. Within a particular perspective, you’ll also see a variety of different editors and views applicable to the work done within that perspective. Don’t worry—we’ll explain how each of these works as we go along.

    Starting Rational Application Developer

    To start Rational Application Developer, select Start Programs IBM Software Development Platform IBM Rational Application Developer IBM Rational Application Developer. When you start Rational Application Developer, a window appears asking which folder you want to use for your workspace (the place where Rational Application Developer saves your work), as shown in Figure 1–3.

    Figure 1–3: The Workspace Launcher window.

    Leave the workspace name set to the default, and click OK. After a few seconds, Rational Application Developer’s Welcome page appears. On the Welcome page, you can click the various icons to see an overview of the Rational Software Development Platform, what’s new in the current version, or tutorials and samples that will teach you how to use the tool. We’ll skip the Welcome information for now, but you can always come back to it by selecting Help Welcome from the Workbench menu.

    Click the X on the Welcome pane tab to close it. The Workbench opens in the J2EE™ perspective. We’ll use the Web perspective to work with Faces Web applications, so click the Open Perspective ) in the toolbar tab along the top right of the Workbench, and select Web from the list of perspectives. If you don’t see Web in the list, select Other…, select Web in the Open Perspective window, and click OK. The Workbench should now look like Figure 1–4.

    Figure 1–4: The Rational Application Developer Workbench.

    Notice that the Workbench is divided into several toolbars and work areas. Let’s take a minute to get familiar with the layout before we continue.

    ) currently appearing in the Workbench. You can have multiple perspectives open at any given time—to switch from one to another, just select its icon. You can also customize this portion of the toolbar by moving it to the left edge of the window or removing the text descriptions now accompanying each icon. To customize, right-click anywhere in the toolbar tab and select the option you want from the context menu.

    Along the top of the Workbench are a series of pull-down menus and a toolbar of common commands used to work within the particular perspective you are using. Because the menus and toolbar match the functions available in a given perspective and the editors being used, they will change as you switch from one perspective to another and work with different editors. The toolbar contains a subset of the actions available from the pull-down menus; you can customize it to add, reorganize, or remove toolbar actions according to your preferences.

    The work areas within the Workbench are also tailored to the functions available in a given perspective and the editors and views being used. In the Web perspective, you will use the Project Explorer to navigate the various folders and files attached to your Web projects. When you open a file, the editor for its file type appears in the center of the Workbench. For example, the Java Editor appears when you are working with Java source files, and the Page Designer appears when you are working with Web pages. Any associated views appear in the other work areas, such as the Properties view and the Palette (which you’ll use to build Faces Web pages). Selection tabs in each work area let you switch from one view to another—for example, to select the Properties view to work with the attributes of the various Faces components within a Web page. You can move views from one work area to another if you prefer a different placement. If you ever find that you’ve customized a perspective more than you intended, you can always select Window Reset Perspective to restore the appearance of the current perspective to its original layout.

    Creating the Project

    Next, you’ll use the Web perspective to create a new Web project to contain your Web application. You’ll create the project as a Dynamic Web project—that is, one that contains dynamic content, such as the Java code for your Web application. You’ll also specify an EAR project (called an Enterprise Application) used for deploying and testing the Web project on an application server.

    To create the project, select File New Dynamic Web Project in the Workbench menu.

    Enter a project name of Survey. Notice that the project location is set to the default for your workspace (the directory specified when you first started Rational Application Developer).

    Make sure the Add project to an EAR check box is checked, and enter SurveyEAR for the EAR project name.

    Select WebSphere Application Server v6.1 for the target runtime, and select Faces Project for the configuration. These options specify that the Web pages in your project will run on WebSphere Application Server v6.1 (the Rational Application Developer Test Environment) and that the project will include the necessary class libraries to create Faces Web pages. The window should look like Figure 1–5.

    Figure 1–5: Creating a Dynamic Web project.

    Click Finish.

    In the Project Explorer, click the plus (+) signs to expand the content of folders in your Survey and SurveyEAR projects, as shown in Figure 1–6.

    Figure 1–6: The Project Explorer.

    Rational Application Developer automatically created a default folder structure for your projects and placed several control files in the folders. The project structure is organized according to the specifications for packaging J2EE applications. A Web project in which you place the actual content for your Web applications uses the standard structure for Web Archive (WAR) files, also called a Web module. An Enterprise project uses the standard structure for Enterprise Archive (EAR) files. When you create a Dynamic Web project, Rational Application Developer associates the Web project with an Enterprise project and places the Web project’s WAR file in the Enterprise project’s EAR file, which you can deploy to an application server.

    You can associate multiple Web projects with a particular Enterprise project, combining related Web modules into one large J2EE application. Luckily, you don’t have to remember all the details for WAR and EAR files, because Rational Application Developer does the packaging for you. Just place your Java source files in Java packages within the Java Resources: src folder, and put the content for your Web pages in the WebContent folder. Rational Application Developer automatically updates the necessary configuration and deployment information for you.

    Creating the Web Application

    The Survey application you’ll build in this chapter consists of two Web pages: an input form, where the user enters their survey information, and a second Web page that echoes the values users enter. To pass data from one Web page to the other, you’ll use a Faces managed bean with a request scope, binding the bean’s properties to Faces UI components in the Web pages. This JavaBean will serve as the object model for your Web application. (In a real application, you’d save the survey information to a database of some sort, but we’ve saved database work until later in the book.)

    Creating the JavaBean

    Follow these steps to create the JavaBean for your Web application:

    To create the Java package and class for your JavaBean, right-click the Java Resources: src folder in the Survey project, and select New Class from the pop-up menu.

    Enter SurveyData for the class name and samples for the package name so that the window looks like Figure 1–7.

    Figure 1–7: Creating the JavaBean for the Survey application.

    Enjoying the preview?
    Page 1 of 1