Getting Started


Defining a VAGen server program

The focus of this section is to finish developing your user interface and connect it to a server application that reads data to be displayed in the Customer Information window. The objective of this section is to familiarize you with making connections between user interfaces and nonvisual parts, such as records and server applications. In addition, you will build the server application and embed the Address panel you created in the previous section. Finally, you will use the interactive test facility to test how the client and server applications work together.

Embedding a reusable visual part

You can now complete the window in Figure 92, which displays detailed customer information.

Figure 92. Customer Information Window

Customer Information Window

To complete the window, add the Address panel you created in Defining the address panel to the Customer Information Window. To add the reusable visual part, perform the following steps:

  1. On the Workbench Projects tab, double-click on TutorialView.

    The Composition Editor opens, displaying the Customer Information window.

  2. From the Beans palette, select Choose bean Choose bean.

    The Choose bean window is displayed

Figure 93. Choose Bean Window

Choose Bean Window

  1. In the Class Name field, type tutorial.ReusableAddressBoxView and select OK.

    The mouse pointer becomes a cross hair.

    Tip:Alternatively, you can select the Browse button and select the class name from the displayed list. The package name is automatically appended for you.
  2. Click on the Customer Information window where you want to add the bean.

    The Address panel is added to the Window.

  3. Size the Address panel (and the Customer Information window if necessary) until the panel fits inside the window.
  4. Select the Address panel with mouse button 2. From the context menu, select Connect>Connectable features.

    The Start connection from window is displayed.

  5. Select Property.
  6. Select StreetFieldText.

    A dotted line with a artwork at the end is displayed.

  7. Select the CUSTOMER Record part.
  8. From the context menu, select Connectable features.

    The End connection to window is displayed.

  9. Select CUSSTREET data and select OK.

    This creates a property-to-property connection between the Street entry field and the data item CUSSTREET in the CUSTOMER Record part.

    By selecting the data property, you are making a connection to only the data contents of the data item. If the connection required a type description in addition to the data contents, you would have selected CUSSTREET, which represents the this property of the data item.

    The entry fields in windows, as in this example, typically only require the data contents. However, when you connect to a parameter in a called parameter list for a program, the data contents and the type description are required.

  10. Repeat the previous steps for CityFieldText, StateFieldText, and ZipFieldText. Connect them to CUSCITY data, CUSSTATE data, and CUSZIP data, respectively.

    This creates property-to-property connections between the fields in the panel and the data items in the CUSTOMER Record part. If you want to check any of the connections, select the connection and the status area will contain a description of it.

Adding a VAGen Program to the visual part

Now that all the user interface parts are in place on the Window, you'll add a VAGen Program part to the free-form surface and connect it to the Find button. The VAGen Program part represents a server program that you will define later in this exercise. The server program will read the customer details from the database and return the data to TutorialView to populate the fields in the Customer Information window.

  1. From the list above the Beans palette, select the VAGen Parts.

    A graphical list of VAGen parts is shown on the Beans palette.

  2. Select the VAGen Program part Figure vagcallf not displayed. and click on the free-form surface outside of your Window.

    The Add Part window is displayed.

  3. In the VAGen part field, type findcus and select OK.

    The FINDCUS program part is now on your free-form surface.

  4. Select the Find button with mouse button 2.

    The context menu for the Find button is displayed.

  5. Select Connect>actionPerformed.

    A line with a artwork on the end is displayed.

  6. Select the FINDCUS program part.

    A context menu is displayed.

  7. From the context menu, select execute.

    A green line with an arrow now connects the Find button with the FINDCUS program part. This connection means that when the Find button is clicked, FINDCUS is called.

  8. Select the FINDCUS program part with mouse button 2.

    A context menu is displayed

  9. Select Open.

    The New Part Package window is displayed

  10. Select the tutorial package and select OK.

    The Program Editor opens to display FINDCUS.

Defining the VAGen server application

In this section you define the VAGen server application FINDCUS, which reads the customer information from a relational database. To retrieve the correct customer information, the record key (CUSNUM) for the database must be passed to the server application from TutorialView. To display the retrieved information, the data to populate the Customer Information window must be returned from the server application. Parameters are the mechanisms by which data is passed between applications.

To define the server application, in the Program Editor, perform the following steps:

  1. From the Define menu, select Called Parameters>Insert Parameter.

    The Insert Parameter window is displayed.

  2. Ensure that the Record radio button is selected, and from the Part Name drop-down list box, select CUSTOMER.
  3. Select OK.

    The CUSTOMER record is displayed in the program diagram under Called Parameters. Now you are ready to define the main functions for FINDCUS.

  4. From the Define menu, select Main Functions.

    The Insert Main Function window is displayed.

  5. In the Part name field, type find-customer and select OK.

    The FIND-CUSTOMER function is displayed in the structure diagram. The ? beside it means that it has not yet been defined.

  6. Double-click on the function icon.

    The New Part Package window is displayed.

  7. Select OK.

    The Function Editor is displayed.

  8. From the I/O Option drop-down list box, select INQUIRY. In the I/O Object field, type custinfo.

    The I/O option and I/O object are displayed on the second line in the Function Editor.

  9. From the Define menu, select Properties.

    The Function Properties window is displayed.

  10. From the Error routine drop-down list box, select EZERTN and select OK.

    The Function Properties window closes. The information retrieved from the database inquiry will be placed in the CUSTINFO record you will define later. The error routine EZERTN will return control to your application when an error occurs. This prevents the application from ending with system generated messages, which might confuse an application user.

  11. In the Function Editor, type the statements as shown in Figure 94.

    The first statement executes before the actual database query. The other statements execute after the query takes place.

Figure 94. Sample Statements

 custinfo.cusnum = customer.cusnum; /*customer number to be retrieved
 ----------------------- INQUIRY CUSTINFO ---------------------
 if custinfo not err;          /*If the query did not return an error
 customer = custinfo;          /*Place all data from the retrieved
 end;                          /*row into the customer record
  1. From the Tools menu, select Validate and Format.

    The statements have been validated and formatted. If a Validation Errors window is displayed, correct the errors listed in the window, and select Validate and Format again.

  2. From the File menu, select Save.
  3. Close the FIND-CUSTOMER function.

    A + is displayed beside the FIND-CUSTOMER function in the Program Editor.

Defining the CUSTINFO record

In the previous section, you defined an INQUIRY function that uses the CUSTINFO record. Now, you need to define the record. This record will contain the detailed customer information after it is retrieved from the database.

  1. In the Program Editor, click the + beside the FIND-CUSTOMER function.

    The CUSTINFO record is displayed.

  2. Double-click on the CUSTINFO record. In the New Part Package window, select OK.

    The Record Editor is displayed.

  3. From the record type drop-down list box, select SQL Row.
  4. Ensure that there are no items in the record. If there is an item in the record, delete it. To delete an item, select it. Then, from the Edit menu, select Delete.
  5. From the Define menu, select Properties.

    The SQL Row Properties window is displayed.

  6. On the SQL Row Properties window, select Insert.

    A row is added and the cursor appears in the Name pane.

  7. In the Name pane, type customer.
  8. Select OK.

    The SQL Row Properties window closes.

  9. From the Tools menu, select Retrieve SQL.

    The SQL table is displayed in the Record Editor.

  10. Click in the Key column of the CUSNUM data item and select the check box.

    The check box is checked. The CUSNUM item is defined as the key data item.

  11. From the File menu, select Save.
  12. Close the Record Editor.

    The fully-defined CUSTINFO record is displayed in the Program Editor.

  13. In the Program Editor, from the File menu, select Save.
  14. Close the Program Editor.

Building parameters for the program

In this section you build the parameters that will be passed between the client view and the FINDCUS program. You also visually connect the parameters to complete the definition.

  1. In TutorialView, select the FINDCUS program part with mouse button 2. From the context menu, select Build parameters from definition.

    Based on the parameter list of FINDCUS, this action creates the parameters needed for the CALL.

    Selecting Build parameters from definition causes defined parameters to be added to the execute method of the FINDCUS program part. The solid green line changes to a dashed green line and a statement displayed in the status line confirms that default parameters were built.

  2. Select the CUSTOMER part with mouse button 2. From the context menu, select Connect>this.

    You now have a line with a spider on the end.

  3. Place the pointer on the JButton1,actionPerformed > FINDCUS,execute connection and click mouse button 1.

    A context menu is displayed.

  4. Select CUSTOMER.

    A purple line is displayed connecting the CUSTOMER record to the FINDCUS program. The dashed green becomes solid

A property-to-property connection connects the CUSTOMER parameter of FINDCUS to the CUSTOMER record. You selected the this property to pass the data contents and the type description of the record to the server application.

Your completed server application should look like Figure 104

Figure 95. TutorialView

Figure viewtutj not displayed.

For more information on building visual parts, refer to the VisualAge for Java online help.

Testing the bean

Now test your bean using the Interactive Test Facility.

  1. From the tool bar, select the Run Figure vjruntst not displayed. button.

    The Customer Information window is displayed.

  2. Place the cursor in the Customer Number field. Type a customer number from the list below; then select Find. Use 111-0101 through 111-0106 and 122-0001 through 122-0003. If you type an invalid number, nothing changes.

    If you want Test Monitor to have focus while it tests your VAGen parts, VAGen Parts Browser, select Window>Options. On the VAGen Test window, under options, select Break on event entry for GUI clients.

    Start the Test Monitor. The Test Monitor gets focus if you have an error in a VAGen part. If you would like to see the Test Monitor window throughout your test run, move it to the right side of your screen.

    If errors are encountered during the test, you can change your code without leaving the test. After you make changes and save the part, the test facility automatically repositions the test for you to test your new changes.

    Otherwise, the program runs and the Customer Information window is updated with data from the database. Your application ran successfully if it looks like the one shown in Figure 96.

  3. Continue entering other customer numbers. After you finish testing, in the Customer Information window, select Cancel.

    The Customer Information window closes.

  4. Close the Test Monitor window.
  5. Close the Composition Editor.

Figure 96. Customer Information Window

Figure jtstcust not displayed.

Summary

Congratulations! You have completed all the steps in this tutorial, and you have experienced first-hand how easy it is to define and test applications using VisualAge Generator. As you begin working with VisualAge Generator, you can refer back to this tutorial, all the other VisualAge Generator documentation, and VisualAge Generator's extensive online help system.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]