GETTING STARTED WITH WEBOBJECTS
Preface 10 Where to Go From Here After you have worked through the tutorials in this book, you should have a good working knowledge of WebObjects. Fo
Chapter 3 Creating a WebObjects Database Application100your relationship, and the relationship’s name is dependent on the adaptor the wizard used. Ada
Refining Your Model1018. Click Connect.EOModeler automatically renames the relationship based on the name of the destination entity. For example, after
Chapter 3 Creating a WebObjects Database Application102At this point your model has all the relationships it needs. The Diagram View gives you an over
Refining Your Model1033. Ensure that the delete rule is set to Cascade.If the wizard created relationships for you, the relationship’s delete rule shou
Chapter 3 Creating a WebObjects Database Application104Enterprise Objects Framework provides several mechanisms for generating and assigning unique va
Setting Up a Master-Detail Configuration105In the Movies application, the master-detail configuration is built around Movie’s movieRoles relationship. T
Chapter 3 Creating a WebObjects Database Application106An Add Display Group panel opens.3. In the Add Display Group panel, change the name to movieRol
Setting Up a Master-Detail Configuration107Notice that the “Has detail data source” box is checked. This means that movieRoleDisplayGroup gets its obje
Chapter 3 Creating a WebObjects Database Application1086. Check the “Fetches on load” box.When “Fetches on load” is selected, the display group fetche
Setting Up a Master-Detail Configuration1091. In the MovieDetails component window, add the bolded text Starring: beneath the Revenue line.2. Below the
Creating a Simple WebObjects Application Chapter 1
Chapter 3 Creating a WebObjects Database Application110When you’re done, the repetition bindings should look like the following:Running MoviesBe sure
Updating Objects in the Detail Display Group111Updating Objects in the Detail Display GroupIn this section, you’ll add the ability to insert, update,
Chapter 3 Creating a WebObjects Database Application112Managing a DisplayGroup’s SelectionRemember how clicking a movie title in the Main page selects
Updating Objects in the Detail Display Group113Adding a FormNow lay out the user interface used to view and edit the selected MovieRole. When you’re d
Chapter 3 Creating a WebObjects Database Application1142. Using the Display Group Options panel, assign talentDisplayGroup’s entity to Talent.Remember
Updating Objects in the Detail Display Group115Talent browser, the selection should refer to a single object. Consequently, you need to add two method
Chapter 3 Creating a WebObjects Database Application116Again because the browser uses a vector for its selections attribute, the setTalentSelection me
Adding Behavior to Your Enterprise Objects1176. Copy the saveChanges method from the Main.java class and paste it into the MovieDetails.java class:pub
Chapter 3 Creating a WebObjects Database Application1181. In EOModeler, inspect the Talent entity.2. In the Entity Inspector for Talent, type Talent i
Adding Behavior to Your Enterprise Objects119Adding Custom Behavior to TalentNow add the fullName method to Talent and bind it to the browser.1. Open
Chapter 3 Creating a WebObjects Database Application120Running MoviesBe sure that all your project’s files are saved (including your model file), and bu
13 This chapter introduces you to the basic concepts and procedures of developing WebObjects applications. You’ll develop, in stages, a simple applic
Chapter 1 Creating a Simple WebObjects Application 14 Project Builder is an integrated software-development application. It contains a project browse
Creating a WebObjects Application Project 15 4. Click Browse.5. In the Save panel, navigate to the DocumentRoot /WebObjects directory. DocumentRoot
Chapter 1 Creating a Simple WebObjects Application 16 9. For Available Assistance, choose None.If you are developing an application that accesses a d
Examining Your Project 17 Examining Your Project Project Builder displays a browser showing the contents of your project. The first column lists sever
Chapter 1 Creating a Simple WebObjects Application 18 3. Select Classes in the first column of the browser. You’ll see three files listed in the second
Launching WebObjects Builder 19 2. Double-click Main.wo in the second column.The application WebObjects Builder launches and displays a window enti
Apple, NeXT, and the publishers have tried to make the information contained in this manual as accurate and reliable as possible, but assume no respo
Chapter 1 Creating a Simple WebObjects Application 20 This pop-up list allows you to switch between graphical editing mode and source editing mode. W
Creating the Page’s Content 21 • Structures . Use these buttons to create paragraphs, lists, images, and other static HTML elements. This setting is
Chapter 1 Creating a Simple WebObjects Application 22 Using the Inspector You use the Inspector window to set properties of the elements in your comp
Creating the Page’s Content23Each element has its own Inspector that allows you to set properties appropriate for the element. The Page Attributes Ins
Chapter 1 Creating a Simple WebObjects Application241. To display the dynamic form elements buttons in the toolbar, choose from the Elements pop-up
Creating the Page’s Content25The window should now look like this:Resizing the Form ElementsThe text fields and text area are a bit small, so you’ll re
Chapter 1 Creating a Simple WebObjects Application261. Inspect the Name text field (that is, select the text field and open the Inspector window). 2. Ch
Binding Elements275. Inspect the multi-line text area. In Text Area Inspector, you can set various attributes corresponding to those of a <TEXTAREA
Chapter 1 Creating a Simple WebObjects Application28WebObjects Builder allows you to declare variables without having to edit your source file directly
Binding Elements29Binding the Input ElementsEach dynamic element contains several attributes. These attributes determine what happens when the element
Contents
Chapter 1 Creating a Simple WebObjects Application30The Inspector window comes to the front, displaying the bindings for the text area. The value attr
Binding Elements313. From the “Page returned” pop-up menu, select null.The value returned by an action method represents the next page (component) to
Chapter 1 Creating a Simple WebObjects Application32Creating the Application’s OutputSo far, you have a way for the guest to enter information and a w
Creating the Application’s Output332. Choose from the Elements pop-up list to display the Structures buttons.3. Click to create a horizontal line
Chapter 1 Creating a Simple WebObjects Application3410. Save your component. It should now look like this:In summary, when the user clicks the Submit
Building and Running Your Application35Building and Running Your Application1. Make Project Builder active. A quick way to do this from WebObjects Bui
Chapter 1 Creating a Simple WebObjects Application366. Click in the Launch panel to launch your application.The Launch Panel displays a series of me
Enhancing Your ApplicationChapter 2
Duplicating Your Project39In the previous tutorial, you learned how to create a web component that has input and output elements and how to bind these
Chapter 2 Enhancing Your Application404. Duplicate the GuestBook folder.On Windows NT, you can do this by selecting the folder, choosing Edit m Copy,
Creating a Custom Guest Class41Creating a Custom Guest ClassIn the first chapter, you created individual variables to store a guest’s name, e-mail addr
Chapter 2 Enhancing Your Application42also a class, specifically a subclass of the class next.wo.Component (called WOComponent in WebScript or Objectiv
Creating a Custom Guest Class436. Double-click the row containing the value binding.This removes the binding for guestName you made previously and bin
Chapter 2 Enhancing Your Application446. Double-click the upper-left cell.You can now edit the contents of the cell. If you want to resume structure e
Creating a Custom Guest Class4511. Click in the component window, then press Tab.Pressing Tab when editing a table causes the contents of the next cel
Chapter 2 Enhancing Your Application46The table should now look like this:3. Save the Main component.Creating the Guest ObjectEarlier in this chapter,
Keeping Track of Multiple Guests474. Save Main.java.5. Build and run your application.The application should work similarly to the first chapter, excep
Chapter 2 Enhancing Your Application48Before doing this, it is important to understand the scope and life span of variables in WebObjects:• Component
Keeping Track of Multiple Guests49Note that there is one method already defined: Application, which is the constructor for the application object. The
v Table of Contents Contents iiiPreface 7 About WebObjects 9About This Book 9Where to Go From Here 10 Creating a Simple WebObjects Application 11 Cre
Chapter 2 Enhancing Your Application503. At the top of the Application class definition, enter this declaration:protected MutableVector allGuests;This
Adding a Second Component51Adding a Second ComponentIn this section, you’ll create a new component. Instead of Java, you’ll implement its code using W
Chapter 2 Enhancing Your Application5210. In the object browser, click application. There is an entry in the second column for the allGuests applicati
Using a Repetition53pageWithName is a standard WebObjects method (defined in the WebApplication class) that allows you to specify a new page to display
Chapter 2 Enhancing Your Application54You’ll bind the allGuests array to the WORepetition’s list attribute. This tells WebObjects to generate the elem
Using a Repetition5511. In the object browser, select application in the first column.12. In the second column, click allGuests and drag the cursor to
Chapter 2 Enhancing Your Application56By using the name currentGuest for the item attribute, you are taking advantage of the fact that the strings in
Adding the Finishing Touches574. Enter the following code before the return statement in clearGuestList:[[self application] clearGuests];This code cal
Chapter 2 Enhancing Your Application585. Select the pageName attribute, then double-click in the Binding column and type (including the quotes) "
Creating a WebObjectsDatabase ApplicationChapter 3
vi Adding the MovieDetails Page 92 Creating the MovieDetails Component 93Storing the Selected Movie 93Navigating from Main to MovieDetails 94Designin
61One of the most powerful features of WebObjects is its ability to provide access to databases. To do so, it uses a framework called the Enterprise O
Chapter 3 Creating a WebObjects Database Application62The Movies ApplicationThe Movies application has two pages, each of which allows you to access i
The Movies Application63Enterprise Objects and the Movies DatabaseEnterprise Objects Framework manages the interaction between the database and object
Chapter 3 Creating a WebObjects Database Application64MOVIE_ROLE table having a MOVIE_ID column. In the MOVIE table, MOVIE_ID is a primary key, while
Designing the Main Page65Designing the Main PageEvery WebObjects application has at least one component—usually named Main—that represents the first pa
Chapter 3 Creating a WebObjects Database Application665. Type Movies in the “File name” field.6. Click Save.7. In the New Project panel, click OK.This
Designing the Main Page67Choosing an AdaptorAn adaptor is a mechanism that connects your application to a particular database server. For each type of
Chapter 3 Creating a WebObjects Database Application683. Complete the login panel.Specify the connection information you provided when you created and
Designing the Main Page69A relationship is a link between two entities that’s based on attributes of the entities. For example, the Movie entity has a
Chapter 3 Creating a WebObjects Database Application703. Uncheck the “Ask about stored procedures” box.Checking this box causes the wizard to read sto
Designing the Main Page71Choosing the Tables to Include1. In the wizard panel, select MOVIE, MOVIE_ROLE, and TALENT in the Tables browser.The wizard c
Chapter 3 Creating a WebObjects Database Application721. Select movieId as the primary key for the Movie entity.2. Click Next.3. Select both movieId a
Designing the Main Page73If foreign key definitions aren’t specified in your database server’s schema information (as with Microsoft Access), the wizard
Chapter 3 Creating a WebObjects Database Application742. Choose Cascade.This option specifies what to do when the source object (the Movie) is deleted.
Designing the Main Page75Choosing a LayoutThe wizard provides several page layout options for formatting objects fetched from the database.1. Choose S
Chapter 3 Creating a WebObjects Database Application76There are three parts to this page: the query part (at the top of the page), which contains field
Designing the Main Page77The order in which you add the attributes determines the order in which they appear on the page, so add them in the following
Chapter 3 Creating a WebObjects Database Application78When the wizard finishes, your new project is displayed in Project Builder. The wizard has produc
Examining Your Project79Examining Your ProjectWhenever you create a new project, Project Builder populates the project with ready-made files and direct
Chapter 3 Creating a WebObjects Database Application80Examining the Variables1. Double-click Main.wo in Project Builder’s WebObjects Components catego
Examining Your Project81Also note the comment explaining how movieDisplayGroup is initialized. The Main.java class doesn’t have any code to create and
Chapter 3 Creating a WebObjects Database Application82Bindings in the Query PartIn the query part of the component, movieDisplayGroup.queryMatch.title
Examining Your Project831. Inspect the hyperlink.Its action attribute is bound to the action method selectObject.2. Look in the Main.java class to see
Chapter 3 Creating a WebObjects Database Application841. Inspect the middle image button.Its action attribute is bound to the action method saveChange
Refining Main.wo85group’s selected object. These changes happen only in memory—not in the database. To actually insert a new row in the database (or de
Chapter 3 Creating a WebObjects Database Application86Specifying a Sort OrderYou can change your application to sort movies alphabetically without wri
Refining Main.wo87Specifying Default Values for New Enterprise ObjectsWhen new enterprise objects are created in your application, it’s common to assig
Chapter 3 Creating a WebObjects Database Application88The Movies application specifies default values for newly created Movie objects using the display
Refining Main.wo89Setting a Number FormatIn addition to a dateformat attribute, text field elements also have a numberformat attribute.1. Inspect the re
9 About WebObjects WebObjects is an object-oriented environment for developing and deploying World Wide Web applications. A WebObjects application ru
Chapter 3 Creating a WebObjects Database Application90Optional ExerciseYou can tidy up the user interface even further by putting the query part of th
Refining Main.wo914. In the Table Inspector, choose Unspecified for the table width.The table resizes to just fit its contents. When you change the cell
Chapter 3 Creating a WebObjects Database Application92Adding the MovieDetails PageThe MovieDetails page shows you the detailed information about a mov
Adding the MovieDetails Page93Creating the MovieDetails Component1. In Project Builder, choose File m New in Project.2. In the New File panel, click t
Chapter 3 Creating a WebObjects Database Application94Movie isn’t actually a class; it’s an entity. It’s listed in the combo box as a type along with
Adding the MovieDetails Page958. In Project Builder, modify the showDetails action to look like the following: public Component showDetails(){ Movi
Chapter 3 Creating a WebObjects Database Application96This adds a new level 3 heading element around the string. The MovieDetails page will show the t
Refining Your Model97telling the application to open the MovieSearch page when the hyperlink is clicked.Running MoviesBe sure that all your project’s fi
Chapter 3 Creating a WebObjects Database Application98Project Builder opens your model file in EOModeler, launching EOModeler first if it isn’t already
Refining Your Model994. In the MovieRole entity, remove movieId and talentId as class properties.5. In the Talent entity, remove talentId as a class pr
Comentarios a estos manuales