+ All Categories
Home > Documents > INTRODUCTION TO APPLICATION DEVELOPMENT WITH ORACLE i FORMS BUILDER

INTRODUCTION TO APPLICATION DEVELOPMENT WITH ORACLE i FORMS BUILDER

Date post: 12-Sep-2021
Category:
Upload: others
View: 5 times
Download: 0 times
Share this document with a friend
22
1 APPENDIX D INTRODUCTION TO APPLICATION DEVELOPMENT WITH ORACLE9i FORMS BUILDER A s you begin to learn the PL/SQL language, it is helpful to view an example of creating an application screen to envision how PL/SQL is used in the application development process. This appendix demonstrates developing screens using the Forms Builder software that is part of the Oracle9i Developer Suite.Two screens will be developed to support the shopper login process on the Brewbean’s Web site.Note that the user login process is discussed in Chapter 5 and the code presented in this appendix will parallel the code previously developed.
Transcript
Page 1: INTRODUCTION TO APPLICATION DEVELOPMENT WITH ORACLE i FORMS BUILDER

1

APPENDIX

DINTRODUCTION TO APPLICATIONDEVELOPMENT WITH ORACLE9i

FORMS BUILDER

As you begin to learn the PL/SQL language, it is helpful to view an exampleof creating an application screen to envision how PL/SQL is used in the

application development process. This appendix demonstrates developingscreens using the Forms Builder software that is part of the Oracle9i DeveloperSuite.Two screens will be developed to support the shopper login process onthe Brewbean’s Web site. Note that the user login process is discussed inChapter 5 and the code presented in this appendix will parallel the codepreviously developed.

Page 2: INTRODUCTION TO APPLICATION DEVELOPMENT WITH ORACLE i FORMS BUILDER

REBUILD YOUR DATABASE

As with all the chapters in the text, your first step is to rebuild the Brewbean’ database.

To rebuild the database:

1. Open SQL*Plus.

2. Enter the following command, which will run all the statements contained inthe appdDbcreate.sql file. Messages verifying the creation and data insertionsteps will scroll on the SQL*Plus screen.

@<pathnameƒtoƒPL/SQLƒfiles>\appendix.d\appdDbcreate

This script file creates and populates only one table, BB_SHOPPER.

CREATE APPLICATION SCREENS FOR THE BREWBEAN’S WEB SITE

The Brewbean’s application allows shoppers to store a profile in the database using theBB_SHOPPER table.To retrieve this information, the shopper must log in using a username and password.This section is a step-by-step example for creating the login portionof the Brewbean’s application with Forms Builder.To achieve this task we will create adata block, canvases, a stored procedure, and a trigger.

Of course, before we can do anything, we must start the Forms Builder, which we willdo next.

Starting Forms BuilderTo start Forms Builder:

1. Go to the Windows Start menu.

2. Locate the entry named Oracle9i Developer Suite – Oracle9iDS.

Select the Forms Developer item.

3. Click the Forms Builder subentry to start the software.

4. The initial screen as shown in Figure D-1 will appear. Note that the ObjectNavigator pane shown operates similar to Windows Explorer.

Note

2 Appendix D

Page 3: INTRODUCTION TO APPLICATION DEVELOPMENT WITH ORACLE i FORMS BUILDER

Introduction to Application Development with Oracle9i Forms Builder 3

5. To be able to test run any application forms created in Developer9i, the Oraclecomponents for Java need to be available. Under the Forms Developer sub-menu, click the Start OC4J Instance entry.

Now that we can start up Forms Builder, in the next section we will explore how tocreate the login application screens within this tool.

Creating a Control Data BlockData blocks are used to manage data from the database or manage items such as text boxesand push buttons placed on the screens or canvases. First, we need to create a data block tohold the items we will place on the canvases to allow the user to enter login information.

To create a data block:

1. Click the Data Blocks node in the Object Navigator and then click theCreate button on the toolbar on the left, as shown in Figure D-2.

2. A dialog box will appear, as shown in Figure D-3. Select Build a new datablock manually and click OK.

Figure D-1 Forms Builder initial window

D

Page 4: INTRODUCTION TO APPLICATION DEVELOPMENT WITH ORACLE i FORMS BUILDER

3. A data block will now appear in the Object Navigator, as shown in Figure D-4.To set the data block properties, right-click the data block node and clickProperty Palette.A property palette as shown in Figure D-5 is displayed. Notethat the names of items created may be different than those shown here.

4. The left side of the property palette lists the property names and the right sidecontains the settings. Find the property named Database Data Blocks, whichcan be set to either Yes or No. Set this property to No.

5. Close the Property Palette.

Now that we have a data block to hold the items placed on the canvases, we will nowcreate the canvases or the user interface screens.

Figure D-3 New Data Block dialog box

Figure D-2 Add a data block

Create button

Data Blocks node

4 Appendix D

Page 5: INTRODUCTION TO APPLICATION DEVELOPMENT WITH ORACLE i FORMS BUILDER

Introduction to Application Development with Oracle9i Forms Builder 5

Figure D-5 Property Palette

Figure D-4 Data Blocks node

D

Page 6: INTRODUCTION TO APPLICATION DEVELOPMENT WITH ORACLE i FORMS BUILDER

Creating Canvases The login portion of the application will require the development of two canvases.Thefirst canvas will contain text boxes that allow the user or shopper to enter a login id andpassword.The second canvas will appear if the login is successful.

To create the canvases:

1. Click the Canvases node in the Object Navigator and click the Create but-ton, as shown in Figure D-6.

2. Right-click the new canvas node and click Property Palette.

3. Set the Name property to LOGIN.

4. Close the Property Palette. Notice the canvas name of LOGIN appears as anode under the Canvases node, as shown in Figure D-7.

5. Double-click the icon located immediately next to the LOGIN canvas nodein the Object Navigator, as shown in Figure D-8.The Canvas Layout Editorwill appear.

Figure D-6 Create a canvas

Create button

Canvases node

6 Appendix D

Page 7: INTRODUCTION TO APPLICATION DEVELOPMENT WITH ORACLE i FORMS BUILDER

Introduction to Application Development with Oracle9i Forms Builder 7

Figure D-8 Canvas Layout Editor

Canvas Layout Editor

Double-click the icon nextto the LOGIN canvas node

Figure D-7 Set canvas properties

LOGIN canvas node

D

Page 8: INTRODUCTION TO APPLICATION DEVELOPMENT WITH ORACLE i FORMS BUILDER

6. Now we will place a text box on the canvas. Click the Text Item button onthe left-side toolbar of the Canvas Layout Editor, as shown in Figure D-9.Then move over the canvas and click where to place the text box.

7. Repeat Step 6 to add the second text box onto the canvas.

8. Double-click the first text box placed on the canvas to open the PropertyPalette, as shown in Figure D-10.

9. Set Name to USER and Database Item to No.

10. Close the Property Palette pane.

11. Double-click the second text box placed on the canvas to open the PropertyPalette.

12. Set Name to PASS and Database Item to No.

13. Close the Property Palette pane.

14. Click the Text button on the Canvas Layout Editor’s left-side toolbar andthen click the canvas above the text boxes, as shown in Figure D-11.

Figure D-9 Adding items to the canvas

Text Item button

Place on canvas

8 Appendix D

Page 9: INTRODUCTION TO APPLICATION DEVELOPMENT WITH ORACLE i FORMS BUILDER

Introduction to Application Development with Oracle9i Forms Builder 9

15. Enter the text of LOGIN.

16. Click the Button item on the Canvas Layout Editor’s left-side toolbar andthen click the canvas below the text boxes, as shown in Figure D-12.

Figure D-11 Adding text on the canvas

Place on canvas

Text button

Figure D-10 Set text box properties

D

Page 10: INTRODUCTION TO APPLICATION DEVELOPMENT WITH ORACLE i FORMS BUILDER

17. Double-click the push button placed on the canvas to open the PropertyPalette, as shown in Figure D-13.

18. Set the Name to LOGIN and the Label to Login. Close the Property Palette.

Figure D-13 Setting push button properties

Figure D-12 Add a push button on the canvas

Add to canvas

Button button

10 Appendix D

Page 11: INTRODUCTION TO APPLICATION DEVELOPMENT WITH ORACLE i FORMS BUILDER

Introduction to Application Development with Oracle9i Forms Builder 11

19. The last item we will place on this canvas will allow us to place a message onthe screen if the user enters an invalid login. Click the Display Item buttonon the Canvas Layout Editor’s left-side toolbar and then click the canvas nextto the LOGIN text, as shown in Figure D-14.

20. Double-click the display item placed on the canvas to open the PropertyPalette and set the properties as follows: Name = LOGIN_REJECT,Maximum Length = 50, Initial Value = Login incorrect, please try again,Database Item = No, and Visible = No. Close the Property Palette.

21. Close the Canvas Layout Editor.

22. Click the Canvases node in the Object Navigator and the Create button tocreate the second canvas.

23. Right-click the new canvas node and click Property Palette.

24. Set Name = WELCOME and confirm that Window = WINDOW1. Closethe Property Palette.

25. Double-click the icon next to the new canvas node to open the CanvasLayout Editor.

26. Add a display item, as shown in Figure D-15.

27. Double-click the display item to open the Property Palette.

28. Set Name = WELCOME and Database Item = No.

29. Close the Property Palette pane.

30. Add a push button to the canvas, as shown in Figure D-16.

Figure D-14 Adding a display item

Display Item button

D

Page 12: INTRODUCTION TO APPLICATION DEVELOPMENT WITH ORACLE i FORMS BUILDER

31. Double-click the push button to open the Property Palette and set Name =TEST_BUT and Label = Test.

32. Close the Property Palette pane.

Figure D-16 Add a push button to the second canvas

Figure D-15 Adding a display item on the second canvas

12 Appendix D

Page 13: INTRODUCTION TO APPLICATION DEVELOPMENT WITH ORACLE i FORMS BUILDER

Introduction to Application Development with Oracle9i Forms Builder 13

Connecting to the Database and Create a Stored Procedure We need to create a stored program unit that will query the BB_SHOPPER table anddetermine if a valid login has been entered into the login screen. To access and workwith any database objects, we will need to connect to the database.

To connect to the database:

1. From the main menu in Forms Builder, click File and then Connect. A logindialog box will appear, as shown in Figure D-17.

2. Enter your Oracle login (such as Scott,Tiger) and a database connection name.The database connection is defined in the TNSNAMES.ORA file.The defaultis orcl for Personal Oracle9i. Click the Connect button.

3. In the Object Navigator, locate the Database Objects node and expand thenode by clicking the plus sign next to the node, as shown in Figure D-18.

4. Locate and expand your schema node, and then click the PL/SQL StoredProgram Units node below your schema.

5. Click the Create button to create a new stored program unit. A dialog boxwill appear requesting the name and type for the program unit, as shown inFigure D-19.

Figure D-17 Login dialog box

D

Page 14: INTRODUCTION TO APPLICATION DEVELOPMENT WITH ORACLE i FORMS BUILDER

6. Type login_sp, click the Procedure option button (if necessary), and thenclick OK.The PL/SQL Editor pane will appear with a basic statement out-line, as shown in Figure D-20.

7. Highlight the code already placed in the editor and press the Delete key toerase it.

Figure D-19 New Program Unit dialog box

Figure D-18 Expand the Database Objects node

Schema node

14 Appendix D

Page 15: INTRODUCTION TO APPLICATION DEVELOPMENT WITH ORACLE i FORMS BUILDER

Introduction to Application Development with Oracle9i Forms Builder 15

8. Enter the procedure code shown in Figure D-21.

9. Click the Save button in the editor to compile the code. Make corrections iferror messages appear.

10. Click the Close button to close the editor.

Figure D-21 Login procedure code

Procedure queries thedatabase to check thelogin information

Figure D-20 PL/SQL Editor pane

D

Page 16: INTRODUCTION TO APPLICATION DEVELOPMENT WITH ORACLE i FORMS BUILDER

Now we have two screens and a stored procedure to verify the login information enteredby a user.The last step is to add code to the Login button to fire off the login procedureand change the screens appropriately. If the login is valid, the second screen that welcomesthe user should be displayed. However, if the login is invalid, the login incorrect messageneeds to be displayed on the login screen.

Adding Triggers to Application Screens For an application to be useful, it will need to respond to user events such as clicking abutton. In Forms Builder, we create triggers that contain PL/SQL code to respond tospecific user events. In this application, we will add a trigger on the Login button.

To add a trigger:

1. Expand the nodes in the Object Navigator until the Triggers node under theLOGIN button is visible, as shown in Figure D-22.

2. Click the Triggers node and then click the Create button. A dialog box asshown in Figure D-23 will appear.This displays all the possible trigger eventsfor a button.

Figure D-22 Triggers node

Triggers node

16 Appendix D

Page 17: INTRODUCTION TO APPLICATION DEVELOPMENT WITH ORACLE i FORMS BUILDER

Introduction to Application Development with Oracle9i Forms Builder 17

3. Type W to quickly advance to the events that start with the letter W, as shownin Figure D-24.

4. Click WHEN-BUTTON-PRESSED, if necessary, and click OK. A blankPL/SQL Editor pane appears, as shown in Figure D-25.

Review and enter the trigger code shown in Figure D-26.

Figure D-24 Button trigger events starting with W

Figure D-23 Trigger events list

D

Page 18: INTRODUCTION TO APPLICATION DEVELOPMENT WITH ORACLE i FORMS BUILDER

5. Click the Compile button and make corrections if needed.

6. Close the PL/SQL editor.

TESTING THE APPLICATION

The last step in our demonstration will be running the application and testing it byentering login values and clicking the Login button.We will want to test both scenarios:a valid and invalid login.

Figure D-26 WHEN-BUTTON-PRESSED trigger code

Trigger added

If login is invalid, displaythe login incorrect messageand remain on thelogin canvas

If login valid, put user’sname in the welcometext and move to thesecond canvas

Trigger code calls thestored procedure

Figure D-25 PL/SQL Editor pane

18 Appendix D

Page 19: INTRODUCTION TO APPLICATION DEVELOPMENT WITH ORACLE i FORMS BUILDER

Introduction to Application Development with Oracle9i Forms Builder 19

To run and test the application:

1. Click the Run Form button on the Forms Builder toolbar, as identified inFigure D-27.The initial login form will appear in a browser window, asshown in Figure D-28.

2. First we need to test an invalid login. Enter charlie and dog, as shown inFigure D-29. After clicking the Login button, the display message shouldappear noting that this is an incorrect login.

Notice that the Login incorrect message is not completely visible. You canreturn to the Layout Editor and increase the size of this item by clicking it anddragging a sizing handle to make it longer. You can also go to the PropertyPalette of this item and set the Width property to an appropriate value.

Note

Figure D-27 Running the application

Run Form button

D

Page 20: INTRODUCTION TO APPLICATION DEVELOPMENT WITH ORACLE i FORMS BUILDER

Figure D-29 Creating an incorrect login

Login incorrect message

Figure D-28 Initial login form

20 Appendix D

Page 21: INTRODUCTION TO APPLICATION DEVELOPMENT WITH ORACLE i FORMS BUILDER

Introduction to Application Development with Oracle9i Forms Builder 21

3. Now enter a valid login of charlie and doghouse and click Login.TheWelcome canvas should appear, indicating a successful login, as shown inFigure D-30.

4. Close the browser window.

5. In Forms Builder, select File, Disconnect from the main menu.

6. Close Forms Builder.

This appendix introduced the process of creating application screens with Oracle FormsBuilder. Most importantly, this highlights the role of PL/SQL in providing all theprocessing logic to support an application.

Figure D-30 Testing a valid login

D

Page 22: INTRODUCTION TO APPLICATION DEVELOPMENT WITH ORACLE i FORMS BUILDER

Recommended