Previous Next Contents Index


Tutorial

This tutorial introduces features of Netscape Application Builder by walking you through the creation of a simple application. This sample application enables users to purchase and sell compact discs.

This tutorial assumes that you have installed Netscape Application Builder 4.0, Netscape Application Server 4.0, Netscape Enterprise Server 3.6 SP1, and LDAP 4.0 successfully, and that your development machine has an HTTP server installed and running. Also, the tutorial database should already be set up by running the tutorial DB scripts. For additional information, such as which drivers to use, how to create ODBC & JDBC data sources, and how to register the tutorial files, see the Netscape Application Builder 4.0 installation instructions.

This chapter includes the following tasks:

Note.
"Using NAB 4.0 with Symantec Visual Café Pro".Task 1: Starting a New Project"> You can use Symantec Visual Cafe Pro to edit, compile, and debug your Java servlets. For more information, see "Using NAB 4.0 with Symantec Visual Café Pro".Task 1: Starting a New Project
This part of the tutorial describes launching Netscape Application Builder, creating a new project, creating a data model to link the application with a database, and saving the project files to disk.

To create a new project, perform the following tasks:

Launch Netscape Application Builder
Launch Netscape Application Builder from the Windows Start Menu by choosing the Netscape Application Builder 4.0 menu item. Netscape Application Builder starts the New Project wizard.

Create a New Project

  1. Name the new project "cdx1" in directory "<nasRoot>\cdx1".
  2. Click Next to create each of the project starter files.
  3. Click Next. The New Project wizard shows you the files it will create.
  4. Click Finish. Netscape Application Builder creates the following files:
Create a Data Model

  1. Click the Yes, Add a Data Model button in the Create Data Model dialog.
  2. Double-click the Data Model icon under New file(s).
  3. Under "Insert Tables" specify the following values for the listed fields:
  4. Click OK and the Add Tables dialog appears.
  5. Add cdxinventory and cdxuser to the Data Model by selecting them from the available tables and clicking the right-arrow button to move them to the "Tables in data model" pane.
  6. Click OK to finish.
Creating Aliases
You will see each table with its list of columns in the Data Model editor.

You are then ready to establish relationships between these tables. In the cdx application, three columns of the cdxinventory table are related to the same column (id) in the cdxuser table.

To represent this in Netscape Application Builder, you create two aliases of the cdxinventory table.

  1. Right-click the cdxinventory table and select Insert Table Alias from the pop-up menu.
  2. Repeat this step to create another table (cdxinventory_3).
Joining Tables
To create the joins, first drag the table boxes so they do not overlap, then perform the following steps:

  1. Click the cdxuser.id field and drag it to cdxinventory.owner. This step creates a one-to-many join from cdxuser.id to cdxinventory.owner.
  2. Next, drag the cdxuser.id field to cdxinventory_2.buyer.
  3. Finally, drag the cdxuser.id field to cdxinventory_3.xlock.
  4. Click the close box [x] to close the data model editor; type the name "cdx.kdm" for this data model, when prompted.
Alternatively, you can access the existing data model. To specify an existing data model, perform the following steps:

  1. Yes, Add a Data Model.
  2. Click the Existing tab.
  3. Select cdx\cdx.kdm.
  4. Double click cdx.kdm in the project tree to view the data model.
Clean Up Project File
Since the tutorial already includes a file named index.html, you need to remove the file of the same name Netscape Application Builder automatically creates for you.

  1. Right-click index.html in the Netscape Application Builder Project tree, and select "Remove".
  2. Check Remove the file from the File System so that the file is deleted.
Add Any Pre-Existing HTML Files
Now, it's time to add any pre-existing HTML files, templates, or images to the project. For this tutorial, we will start with the files installed in <nasroot>/APPS/GXAPP. To add these pre-existing HTML files to the tutorial application, perform the following steps:

  1. Using Windows Explorer, copy the files and sub-folders in <NABroot>\tutorial\starters to the working project directory under <WebRoot>\docs\cdx1.
  2. Using Netscape Application Builder, select Project - Add File(s) then select the Existing tab to add existing files to the project.
  3. Select the Existing tab and, Under Web Server root\cdx1, select the following files:
  4. Click Add. Netscape Application Builder adds the files to the project.
Note. You must copy the logo image file to your project directory as well, so that .jsp templates will properly display the logo.

The cdx\templates subdirectory includes a Macromedia Dreamweaver template that can be applied within Dreamweaver to the pages generated by Netscape Application Builder. You do not need to add this file to your Netscape Application Builder project.

Save Your Work
Now is a good time to save your work.

Click the double-disk toolbar icon to save all project files. If the Save All option is not enabled, then Click Save.


Task 2: Creating Static Links
Netscape Application Builder provides easy-to-use code generation wizards to create sets of HTML and JavaServer pages, servlets, and database queries. To use these wizards most effectively, it is best to think of your application in terms of activities, and from there, map each activity to the use of one or more Wizards.

This tutorial illustrates this process as you first create and link in the activities for the Main Menu page and the User Menu page. The primary difference between these pages, is that the User Menu page presents some activities that require a user to have previously logged in.

Create and/or Link the Destinations for the Main Menu (index.html)

  1. From the Project tree, double-click the HTML Page "index.html" to open it in Netscape Application Builder's integrated HTML editor.
  2. Select the text of the first bullet: Instructions.
  3. Click the Create Link icon at the far right of the toolbar. If the Create Link icon is not present, then select View - Toolbars - Standard. Note that you can also right-click the highlighted text and choose "Create Link" from the pop-up menu to create the link.
  4. In the Properties inspector, click the Destination URL property editor button .
  5. In the HTML File drop-down, select the file Instructions.html.
  6. Click OK to complete the link.

Task 3: Creating an Input Form
To create the "New Account" data entry form, perform the following tasks:

Generate a Data Entry Form and Associated Servlet
For the new account activity, use the Input Wizard to generate a data entry form and a servlet to process the form data.

  1. Select File - New - Input.
  2. Type "CreateAccount" for Name.
  3. Store to a database table.
  4. Select the project data model (cdx.kdm).
  5. Select Use the existing connection and verify that the name is "cdx".
  6. Select the table cdxuser to specify name, email, phone, and password fields for stored input data (uncheck "id" so it does not appear on the form).
  7. Click Next.
  8. Click Finish.
Edit the JavaServer Page
Next, edit the CalledCreateAccount.jsp response page to add an identifying message and a link to index.html.

  1. To create link, drag Data-bound HTML HyperLink icon from palette.
  2. Change link text to "Main Menu".
  3. Click the Create Link icon at the far right of the toolbar. If the Create Link icon is not present, then select View - Toolbars - Standard. Note that you can also right-click the highlighted text and choose "Create Link" from the pop-up menu to create the link.
  4. In the Properties inspector, click the Destination URL property editor button .
  5. In the HTML File drop-down, select the file "index.html".
  6. Click OK to complete the link.
Edit the Query File

  1. Double-click CalledCreateAccount.gxq in Project tree to open the query file.
  2. Double-click the CalledCreateAccount_Insert query.
  3. Click the Fields tab, and set the Value for the "id" column to be :id.
  4. Click Finish
  5. Screen shot is out-of-date for Beta II.

Edit the Servlet File
Finally, you need to add the code to set the "id" parameter in the servlet, CalledCreateAccount.java.

  1. Double-click the CalledCreateAccount.java file to open it.
  2. Find the defaultAction() method and before the stmt.executeUpdate() statement, add the following code to the servlet file:
  3. Save all modified files.
  4. Compile (and Test, if desired).
Add the Main Menu Link
Add the Main Menu Link to the Create Account Page.

  1. Select "Create New Account" text in index.html.
  2. Click the link icon.
  3. Select the destination URL Property Editor .
  4. Select the html page CreateAccount.html.

Task 4: Creating a Login Sequence
To create the login page and associated servlet, perform the following tasks:

Create the Login Page and Servlet to Process Login Data

  1. Select File - New - Login.
  2. Type "Login" for Name.
  3. The username and Password parameters are already specified; select Next.
  4. Check Authenticate with a Database Table.
  5. Select the project's data model (cdx.kdm).
  6. Select Use the existing connection and verify that the name is "cdx".
  7. Select Table "cdxuser" and bind Username and Password to name and pswd columns, respectively; click Next.
  8. Make sure "id" and "name" are checked to save to session.
  9. Click Next.
  10. Click Finish.
Modify CalledLogin.java File
Modify the CalledLogin.java file to access id from ResultSet.

The Login Wizard expects the value saved to the session to be input data from the Login.html form. You need to replace the generated code with code that pulls "id" from the user's cdxuser database entry.

Compile

  1. To compile, select Build - Compile File.
Link the Login Page to the Main Menu

  1. Open index.html.
  2. Select Log In and specify it as a link.
  3. Click the link icon.
  4. Select the destination URL Property Editor .
  5. Select the html page Login.html.

Task 5: Creating a Database Form
Create the List Users destination.

  1. Select File - New - Database Forms.
  2. Type "ListUsers" for Name.
  3. Click Next.
  4. Click Next to use an existing data model.
  5. Select Single page, Multiple record master.
  6. Specify the project's data model (cdx.kdm).
  7. Select Use the existing connection and verify that the name is "cdx".
  8. Select the cdxuser table and the name, email, and phone fields.
  9. Select display all records at once.
  10. Select cdxuser.name to sort.
  11. Click Next.
  12. Click Finish.
  13. Open ListUsers.jsp and add a link back to the main menu:
  14. Open index.html and convert List Users static text to a link:
Note.
Task 6: Creating Browse Activities
To create the browse activities, perform the following tasks:

Create Browse Titles By Artist Activity

  1. Select File - New - Database Forms.
  2. Type "BrowseArtist" for Name.
  3. Click Use a data model.
  4. Select Single page, Multiple Record Master.
  5. Specify the project's data model (cdx.kdm).
  6. Select Use the existing connection and verify that the name is "cdx".
  7. Select table: cdxinventory.
  8. Select table fields: id, artist, title, and price.
  9. Select Browse 20 records at a time.
  10. Select Sort by cdxinventory.artist.
  11. Click Next.
  12. Click Finish. Netscape Application Builder creates the following files:
Adding Select Conditions
Now we need to edit the query to only display available CDs. In the data model, CDs that have already been purchased or are pending purchase will be marked with the buyer's id in the buyer or xlock field.

  1. Open the query, BrowseArtist.gxq; double-click the BrowseArtist select query; and select the Conditionals tab on the query properties dialog.
  2. Click Add Condition.
  3. Select the cdxinventory table, buyer field, and = operator, and enter "0" as the value. Note that you must not include quotes around the values.
  4. Click OK, then repeat steps 1 and 2 for the xlock field. The Conditions panel of the Query Designer displays the new query conditions; then click Finish.
Converting a Column to Links
Convert the id column to the Buy! link in the BrowseArtist.jsp file:

  1. Open BrowseArtist.jsp.
  2. Select BrowseArtist.id data-bound label.
  3. Delete it.
  4. Enter text "Buy!".
  5. Select the text "Buy!".
  6. Click the Create Link icon at the far right of the toolbar. Note that you can also right-click the highlighted text and choose "Create Link" from the pop-up menu to create the link.
Note that after you create the Buy! activity (see: Task 8: Using Queries and Result Sets) you will use the Destination URL property editor to complete the data-bound link.

Create Browse Titles By Price Activity

  1. Select File - New - Database Forms.
  2. Type "BrowsePrice" for Name.
  3. Click Use a data model.
  4. Select Single page, Multiple Record Master.
  5. Specify the project's data model (cdx.kdm).
  6. Select Use the existing connection and verify that the name is "cdx".
  7. Select table: cdxinventory.
  8. Select table fields: id, artist, title, and price.
  9. Select Browse 20 records at a time.
  10. Select Sort by cdxinventory.price.
  11. Click Next.
  12. Click Finish. Netscape Application Builder creates the following files:
Adding Select Conditions

  1. Open the query, BrowsePrice.gxq; double-click the BrowsePrice select query; and select the Conditionals tab on the query properties dialog.
  2. Click Add Condition.
  3. Select the cdxinventory table, buyer field, and = operator, and enter "0" as the value. Note that you must not include quotes around the values.
  4. Click OK, then repeat steps 1 and 2 for the xlock field. The Conditions panel of the Query Designer displays the new query conditions; then click Finish.
Converting Columns to Links
Convert the id column to the Buy! link in the BrowserPrice.jsp file:

  1. Open the BrowsePrice.jsp file.
  2. Select BrowsePrice.id data-bound label.
  3. Delete it.
  4. Enter text "Buy!".
  5. Select text "Buy!".
  6. Click the Create Link icon at the far right of the toolbar. If the Create Link icon is not present, then select View - Toolbars - Standard. Note that you can also right-click the highlighted text and choose "Create Link" from the pop-up menu to create the link.
Note that after you create the Buy! activity (see: Task 8: Using Queries and Result Sets) you will use the Destination URL property editor to complete the data-bound link.

Connect Main Menu Links to the Browse Activities
To connect the Main menu links to the Browse By Artist & Browse by Price activities, perform the following steps:

  1. Open UserMenu.html.
  2. Select the text to become a link, either Browse Available Titles [Sorted by Price] or Browse Available Titles [Sorted by Artist].
  3. Click the Create Link icon at the far right of the toolbar. If the Create Link icon is not present, then select View - Toolbars - Standard. Note that you can also right-click the highlighted text and choose "Create Link" from the pop-up menu to create the link.
  4. Bring up Destination URL Property Editor from Properties
  5. Select BrowseArtist or BrowsePrice servlet as necessary.
  6. Repeat steps 2-5 for the other link.

Task 7: Creating a Search Activity
Now you are ready to create the User Menu activities. You will also create the "Buy CD" activity and connect it to the "Browse CD Buy!" links. To perform this task, you need to create the CD Browser master/detail/search set, which is designed for browsing after login with view of owner detail for purchase.

  1. Select File - New - Database Forms.
  2. Type CDBrowser for Name; click Next.
  3. Select the option "Use a data model" to use cdx.kdm and click Next.
  4. Select Multiple record master and single record detail.
  5. Select the "Create a search page" checkbox.
  6. Specify the project's data model (cdx1.kdm).
  7. Select "Use an existing connection" and verify that the name is cdx.
  8. Select fields to display in master in the following order:
  9. Select browse 20 records at a time.
  10. Select sort by cdxinventory.artist and cdxinventory.title.
  11. Select fields to display on detail:
  12. Leave detail fields display-only.
  13. Select cdxuser.name for Display Field; this is the drill-down field.
  14. Specify join as (Master) cdxinventory.owner = (Detail) cdxuser.id.
  15. Specify columns for search page: title and artist.
  16. Screen is out-of-date for Beta II

  17. Click Next.
  18. Click Finish.
Modifying a SQL Query
Next, you need to edit the generated query, CDBrowser.gxq to ensure that only CDs that are available for purchase are displayed.

  1. Open the CDBrowser.gxq query file.
  2. Screen is out-of-date for Beta II

  3. Double-click the CDBrowser select query. This time, the Conditionals panel is disabled because the query includes the variable ":Whereclause" and is considered a custom query.
  4. Select the SQL panel where you can enter the additional where conditions directly into the SQL SELECT statement.
  5. Edit the statement to include the conditions:
Editing a JavaServer Page
Edit the CDBrowser.jsp JavaServer page as follows:

  1. Delete the "id" text in column header.
  2. Select CDBrowser.id data-bound label.
  3. Delete it.
  4. Enter text "Buy!".
  5. Select text "Buy!".
  6. Click the Create Link icon at the far right of the toolbar. If the Create Link icon is not present, then select View - Toolbars - Standard. Note that you can also right-click the highlighted text and choose "Create Link" from the pop-up menu to create the link.

Task 8: Using Queries and Result Sets
To create the Buy! browse activities, perform the following tasks:

Create SELECT Query
To create a SELECT query to specify purchase item, perform the following steps:

  1. Select File - New - Query.
  2. Type cdrecord for Name.
  3. Specify the project's data model (cdx.kdm).
  4. Specify Select for Type.
  5. Using the SelectQuery Properties dialog, perform the following actions:
  6. Click Finish.
Create UPDATE Query
To create an UPDATE query for locking the purchase, perform the following steps:

  1. Select File - New - Query.
  2. Type updatelock for Name.
  3. Specify the project's data model (cdx.kdm).
  4. Select Update for the query type.
  5. Using the UpdateQuery Properties dialog, perform the following steps:
Netscape Application Builder creates the updatelock.gxq UPDATE query file.

Create New Database Form

  1. Select File - New - Database Forms.
  2. Type BuyCD for Name.
  3. Select cdrecord.gxq query.
  4. Select "Multiple Records" to get a tabular layout.
  5. Do not check the "Create input page" checkbox.
  6. Click Next.
  7. Click Finish.
Netscape Application Builder creates the BuyCD.jsp, BuyCD.java, and BuyCD.ntv files.

Edit BuyCD JavaServer Page

  1. Open the BuyCD.jsp file to remove unwanted columns from the page.
  2. Place cursor in the first row, first column of the table, and select Format - Table - Delete Column to remove the id column.
  3. Repeat step 2 to delete the owner, buyer, xlock, and genre columns.
  4. From the Palette Form tab, drag a push button component below the table.
  5. Use the Properties editor to change the Label property to Buy It!.
Edit BuyCD Servlet

  1. Open up BuyCD.java file.
  2. From the properties inspector, using the parameter properties editor, add a required session parameter named id.
  3. Using the properties editor, add the required session variable, id, by clicking the expand box next to the Required Sessions property and selecting id as the value of [new item].
Edit BuyCD ResultSet

  1. Open the BuyCD.java file.
  2. Using the Properties editor, edit the BuyCD Output ResultSet.
  3. Select the Inputs tab and make the following selections for the Query:
Edit DefaultAction Method
Using the code editor, edit the defaultAction() method to incorporate the super.defaultAction code directly (from the project's BaseServlet.java file). Subsequently, if validation fails, you can display your own error page (NoLogin.jsp). Replace the call to super.defaultAction with code similar to the following:

Note. You must copy the NoLogin.jsp file from your cdx directory to your cdx1 directory if you have not already done so. You can use Windows Explorer for this purpose.

After the BuyCD page is presented and the user confirms the purchase, the BuyCommit servlet updates the cdxinventory table and sends mail to the seller.

Create Transaction Confirmation Page
Next, you will use the Netscape Application Builder Results wizard to get started on the BuyCommit servlet and transaction confirmation page.

To create the transaction confirmation page, perform the following tasks:

Launch Results Wizard to Create BuyCommit Page

  1. Select File - New - Results.
  2. Type BuyCommit for Name.
  3. Enter the input parameter id and check Required.
  4. Click Next.
  5. Click Finish.
Note. You may want to use your favorite Java editor to implement the following code changes. You can customize the editor Netscape Application Builder uses to edit Java files by displaying the Tools - Development Options dialog box. For more information, see "Setting Development Options".

  1. Add code to your BuyCommit.java file. This code contains the defaultAction() method. You will find this code in the completed file installed in <NASRoot>\Apps\cdx\BuyCommit.java.
  2. In this code, you must change the directories for cdrecord.gxq, updatelock.gxq, and CDBrowser.gxq from cdx to cdx1:
Link BuyCommit to the BuyCD Confirmation Page
Next, you need to link the BuyCommit servlet to the BuyCD confirmation page.

  1. Open the BuyCD.jsp file.
  2. Select Form: Form1.
  3. Open Action property editor:
    1. Select Action.
    2. Click within the rightmost part of a blank field to activate the custom property button .
    3. Click the property button .
    4. Select BuyCommit from the servlet drop-down list.
      

  4. Click the Get Arguments button.
  5. Click in value field and click the Data-Bind Value button.
  6. Netscape Application Builder displays the cell editor dialog box with ResultSet BuyCD and DataField id already selected. Click Add and then click OK to specify the data-binding expression.
  7. Click OK on the main property editor dialog.
The Buy! Activity is now complete. Next, return to Browse pages to connect the "Buy!" JSP to the BuyCD servlet.

Link Buy! to BuyCD Servlet

  1. Open the BrowseArtist.jsp file.
  2. Select Buy! to edit the Destination URL property.
  3. Select the BuyCD servlet.
  4. Click the Get Arguments button, select value cell, and select Data Bind-Value.
  5. In the cell editor dialog box, select BrowseArtist in the ResultSet drop-down list and select id in the DataField drop-down list; click Add.
  6. Netscape Application Builder displays the GX tag data-binding expression; click OK.
  7. Click OK in the main dialog box.

Task 9: Inserting Form Data Into a Database
To add the "CD for Sale/Exchange" buyer destination functions, perform the following steps:

  1. Select File - New - Input.
  2. Type "CreateEntry" for Name.
  3. Store to a database table.
  4. Specify the project's data model (cdx.kdm).
  5. Use an existing connection (cdx).
  6. Select table cdxinventory; select the following fields: price, title, artist, and notes, to appear on the form.
  7. Click Next.
  8. Click Finish.
Editing Called Code

  1. Open CalledCreateEntry.java, in the properties editor and add the required session variable, id.
  2. Enter the following code prior to the stmt.executeUpdate() in the CalledCreateEntry.java file to bind the CD inventory id and owner id to the query parameters:
Creating a Custom Query
To edit CalledCreateEntry.gxq to create the CalledCreateEntry_Count custom query perform the following steps to:

  1. Open the CalledCreateEntry.gxq file.
  2. Right-click the view and select the Insert Select Query pop-up menu item.
  3. In the SelectQuery Properties dialog, name the query "CalledCreateEntry_Count".
  4. Select the SQL tab and edit the SQL statement to read:
  5.    /* CalledCreateEntry_Count:  */
    
       query CalledCreateEntry_Count using (ODBC, cdx, netscape) is 
    
       select count(*) 
    
       from cdxinventory
    

  6. Click Finish. The query is now a custom query.
Editing Insert Query Properties
With the CalledCreateEntry.gxq still open in the Query Editor view, double-click the CalledCreateEntry_Insert file to display the InsertQuery Properties dialog box.

You now need to add the id, buyer, and xlock fields to the query; setting id to the new record identifier and initializing the buyer and xlock fields
to 0.

  1. Select to the SQL tab and edit the SQL statement to contain the following code:
Linking an HTML File
To link the "Add CD for Sale" item to the Create Entry page:

  1. Open the UserMenu.html file.
  2. Select the text "Add CD for Sale/Exchange".
  3. Click the Create Link icon, or right-click the text selection and choose Create Link from the pop-up menu.
  4. From the Properties editor, open the Destination URL property editor.
  5. Select CreateEntry.html from the HTML File drop-down list.
  6. Click OK to complete the link.

Task 10: Using Queries With Database Forms
Since the queries for this report are more complicated than for previous reports, this tutorial first uses the query editor to create the queries. Then, we use the Database Form wizard to use the generated queries. Recall that in the data model, the alias cdxinventory_3 is joined by xlock to user. For the required SELECT query, you need to take any inventory fields from this alias because the xlock field identifies CDs with pending transactions.

To create the "view pending transactions" activity, perform the following tasks:

Create SELECT Query
First you need to create a query for the report itself.

  1. Select File - New - Query.
  2. Type PendingSeller for Name.
  3. Specify the project's data model (cdx.kdm).
  4. Specify Select for Type.
Selecting Query Properties
Using the SelectQuery Properties dialog box, perform the following steps:

  1. Type PendingSeller for Name.
  2. Select the title, artist, and price fields from the cdxinventory_3 table. Note that you choose the cdxinventory_3 table to display related information about the prospective buyer.
  3. Select name from the cdxuser table.
  4. Select id and xlock from the cdxinventory_3 table.
Specifying Select Conditions
To add conditions for the select query:

  1. Click Add Condition to add the following conditions:
  2. Click Finish.
Netscape Application Builder creates the PendingSeller.gxq query file.

Create UPDATE Query
Next, you need to create an UPDATE query to accept the transaction and sell the CD.

  1. With the PendingSeller query view still active, select Insert - Update Query from the menu or by right-clicking in the query window.
  2. Type AcceptSale for Name.
  3. Fields: using the cdxinventory table, set fields buyer and xlock to:
  4. Click Add Condition to add the following condition:
  5. Click Finish.
Netscape Application Builder adds the query to the query file.

Next, you need another UPDATE query to cancel a sale.

  1. With the PendingSeller query view still active, select Insert - Update Query from the menu or by right clicking in the query window.
  2. Type CancelSale for Name.
  3. Fields: set field xlock to:
  4. Click Add Condition to add the following condition:
  5. Click Finish.
Netscape Application Builder adds the query to the query file.

Build Pending Sales Report
Now you are ready to build the pending sales report.

  1. Select File - New - Database Form.
  2. Type PendingSeller for Name.
  3. Specify the existing query file: PendingSeller.gxq.
  4. Specify Parent query: PendingSeller.
  5. Specify Multiple records.
  6. Do not check "Create input page".
  7. Click Next.
  8. Click Finish.
Netscape Application Builder creates the PendingSeller.java, PendingSeller.ntv, and PendingSeller.jsp files.

Adding a Required Session Variable
Create the id session variable and edit the PendingSeller Output ResultSet to bind the owner query parameter to the id session variable.

  1. Open the PendingSeller.java file and using the property editor, add a new required session variable: id.
  2. Select the Inputs tab and following selections for the Query Parameter owner:cdrecord:
  3. Click Finish.
Converting Fields to Links
You need to convert the id and xlock fields in the report to "Sold" and "Cancel" links, which enable the user to accept or cancel the sale:

  1. Open the PendingSeller.jsp file.
  2. Edit the column headers for the last two columns by selecting the field identifier text, and replacing it with "Accept" (5th column) and "Cancel" (last column).
  3. Right-click the PendingSeller.id4 data-bound label and, using the pop-up menu, select Change Type - Data-Bound Link.
  4. Repeat step 2 for the PendingSeller.xlock data-bound label.
  5. Now, click again on the PendingSeller.id4 data-bound label and, in the Properties editor, clear the ResultSet property by selecting and deleting the text "PendingSeller".
  6. Now you can enter the Link text: Cancel.
  7. Similarly, set the Link text for Accept link to Sold!.
Create AcceptSale Servlet
Before you can fill in the Destination URL properties for the two prior management links, you need to create two servlets, one that accepts the transaction, and one that cancels it. (You create the CancelSale servlet in "Create CancelSale Servlet" on page 211.) For such servlets that return simple confirmation pages, you can use the Netscape Application Builder Results wizard.

  1. Select File - New - Results.
  2. Type AcceptSale for Name.
  3. To execute the AcceptSale query, you need the id and buyer inputs, so specify these parameters as required inputs.
  4. Click Finish.
Netscape Application Builder creates the AcceptSale.java, AcceptSale.ntv, and AcceptSale.jsp files.

Edit Servlet to Load and Execute Update Query
Next, you need to enter the code necessary to load and execute the associated query from the query file. You will find this code in the completed file installed in <NASRoot>\Apps\cdx\AcceptSale.java.

This code is similar to the Insert or Update code produced for a data-entry form by the Database Form Wizard of the Input Wizard.

After you copy the code, you must make the following changes:

  1. In AcceptSale.java, change the directories for PendingSeller.gxq and AcceptSale.jsp from cdx to cdx1:
Create CancelSale Servlet
To create the CancelSale servlet, use the Results wizard and perform the following steps:

  1. Select File - New - Results.
  2. Type CancelSale for Name.
  3. For inputs, add the required parameter, id.
  4. Click Finish.
Netscape Application Builder creates the CancelSale.java, CancelSale.ntv, and CancelSale.jsp files.

Edit Servlet to Load and Execute Update Query
Next, you need to enter the code necessary to load and execute the associated query from the query file. You will find this code in the completed file installed in <NASRoot>\Apps\cdx\CancelSale.java and <NASRoot>\Apps\cdx\AcceptSale.java.

After you copy the code, you must make the following changes:

  1. In CancelSale.java, change the directories for PendingSeller.gxq and SellerCancel.jsp from cdx to cdx1:
This code is similar to the Insert or Update code produced for a data-entry form by the Database Form Wizard of the Input Wizard.

Connect Links to Servlets
Next, return to the PendingSeller.jsp file to connect the Sold! and Cancel links to the update servlets. Start by opening the PendingSeller.jsp file.

Connecting the Sold! Link
Click the Sold! link and edit the Destination URL property:

  1. In the Servlet drop-down list, select the AcceptSale servlet.
  2. Click the Get Arguments button.
  3. Click in the id value cell, then click the Data-bind value button.
  4. In the cell editor drop-down lists, select the PendingSeller ResultSet and the DataField, id4.
  5. Click Add, then click OK.
  6. Repeat steps 3-5 for the buyer value, selecting xlock3 in the cell editor as the source DataField.
  7. Click OK on the main property editor to complete the Sold! URL specification.
Connecting the Cancel Link
Continuing with the Cancel link, click Cancel and, again, edit the Destination URL with the URL property editor:

  1. In the Servlet drop-down list, select the CancelSale servlet.
  2. Click the Get Arguments button.
  3. Click in the id value cell, then click the Data-bind value button.
  4. In the cell editor drop-down lists, select PendingSeller ResultSet and the DataField, id4.
  5. Click Add, then click OK.
    1. Click OK on the main property editor to complete the Cancel URL specification.
Link View Pending Transactions Activity to User Menu
This completes the View Pending Transactions activity; you can now return to the User Menu and hook up the associated link.

  1. Open the usermenu.html file.
  2. Select the text of the "View pending transactions on your CDs" bullet.
  3. Click the Create Link icon at the far right of the toolbar. If the Create Link icon is not present, then select View - Toolbars - Standard. Note that you can also right-click the highlighted text and choose "Create Link" from the pop-up menu to create the link.
  4. Display the Destination URL property editor, and select the servlet PendingSeller.
  5. Click OK.
Replace the Called Login JSP
Note. Once you have completed the UserMenu.html file, perform the following steps:

  1. Replace the source of CalledLogin.jsp with a copy of UserMenu.html.
  2. Open the source view of UserMenu.html; select all of the text and copy.
  3. Open the source view of CalledLogin.jsp, select all text.
  4. Paste.

Task 11: Creating Enterprise JavaBeans
Netscape Application Builder allows you to create Enterprise JavaBeans or import existing JavaBeans from jar files. This task shows you how to create a session bean using the Session Bean wizard.

Choose New from the File menu and select Session Bean. You can enter the name and directory in which you want to store the bean.

  1. Choose CreditCheckBean for the name of the bean.
  2. Create it in the myBeans directory at a level parallel to the cdx directory. Note that Netscape Application Builder does not create the folder for you.
The directory specifies the package that contains the bean. The name specifies the names of the bean class and interfaces. You can change the class and interface names in the next panel in the dialog box. You can also specify control descriptors as well.

  1. Click Next.
No changes are required for this example.

The next dialog box allows you to specify whether the bean is a stateful or stateless session bean.

  1. Choose Stateless.
  2. Click next to finish the wizard and create the files.
  3. Click Finish.
  4. Edit the bean's interface file to define the CheckCredit() method.
  5. Add an implementation of the CheckCredit() method to the CreditCheckBeanBean.java file.
  6. Rebuild your project.
  7. Modify the BuyCD class to use the credit check session bean.
You have now finished constructing the CD Exchange tutorial application.

 

© Copyright 1999 Netscape Communications Corp.