[精]Oracle APEX 5.0 新手教程(一) Form表单

Oracle APEX Tutorial for Beginners (APEX 5.0)
1-  Introduction
2-  Create Workspace
3-  Work with Workspace
4-  User and Group Management in Workspace
5-  View table and data
6-  Create Application
6.1-  Create Database Desktop Application
6.2-  Create your first page
6.3-  Create a page from scratch
7-  Oracle APEX Programming Tutorial (continue)

1- Introduction

In this document, I will instruct you to work with  Oracle Application Express (Oracle APEX) 5.x:
You can see instruction document of installing and configuring  Oracle APEX on:

2- Create Workspace

First, you need to log in the administration system of  Oracle APEX in order to declare a  Workspace. A  Workspace will work with a  SCHEME in database.  Workspace contains Applications (including a system of forms, reports, and so on), managing users who participate in programming, or users who use the application.
  • http://localhost:8080/apex/apex_admin
[精]Oracle APEX 5.0 新手教程(一) Form表单_第1张图片
You need to create new  Workspace:
Enter:
  • Workspace Name: DEV_WORKSPACE
  • Workspace ID: 1234567

 
[精]Oracle APEX 5.0 新手教程(一) Form表单_第2张图片
You can select a SCHEMA available in Database. Here I create a new SCHEMA named  DEV with password  dev123.
[精]Oracle APEX 5.0 新手教程(一) Form表单_第3张图片
In the previous step, you created a  SCHEMA named  DEV. It means 1  user database is created and named  DEV.

In this step, you need to declare a administration User of  Workspace. It is not a  user database, but it is a administration user of this  Workspace. It is capable of creating applications, other Users as programmers, or users who use the application... 
[精]Oracle APEX 5.0 新手教程(一) Form表单_第4张图片
[精]Oracle APEX 5.0 新手教程(一) Form表单_第5张图片
[精]Oracle APEX 5.0 新手教程(一) Form表单_第6张图片
Your Workspace has been created. You can see the list of current Workspace and edit if you want.
[精]Oracle APEX 5.0 新手教程(一) Form表单_第7张图片

3- Work with Workspace

In the above step, you created a Workspace named  DEV_WORKSPACE. Now we will log in and work with this Workspace.
  • http://localhost:8080/apex
Enter:
  • Workspace: DEV_WORKSPACE
  • User Name: devadmin
  • Password: devadmin123
[精]Oracle APEX 5.0 新手教程(一) Form表单_第8张图片
In the first time of logging in Workspace, the system require you to change your password, but you can keep your password intact.
You are logged in  DEV_WORKSPACE Workspace.

4- User and Group Management in Workspace

After logging in   Workspace as an acting admin, you can create  users and  groups for Workspace.
[精]Oracle APEX 5.0 新手教程(一) Form表单_第9张图片
Enter:
[精]Oracle APEX 5.0 新手教程(一) Form表单_第10张图片
[精]Oracle APEX 5.0 新手教程(一) Form表单_第11张图片
User  dev01 has been created.
[精]Oracle APEX 5.0 新手教程(一) Form表单_第12张图片
Now you can log out the system in order to log in with user  dev01. You are now ready for programming  Oracle APEX.

5- View table and data

You need to log in with a user as the role of a programmer.
  • http://localhost:8080/apex
[精]Oracle APEX 5.0 新手教程(一) Form表单_第13张图片
Look at Objects in Schema through  Object Browser.
In the previous step, you created Schema  DEV through  Oracle APEX. This schema currently has system tables and some DEMO tables available in   Oracle APEX, and some related  Sequences.
[精]Oracle APEX 5.0 新手教程(一) Form表单_第14张图片

6- Create Application

In  Oracle APEX, you can create an application in accordance with one of three types:
  1. Desktop Application
  2. Websheet Application
  3. Mobile Application
For a beginner  Oracle APEX,  it is best to have an example with  Database Desktop Application. In fact, this application still runs on the web but its interface is quite similar to a typical Desktop application.
In this document, I instruct you to create a  Hello World Oracle Apex application in form of  Database Desktop Application.

6.1- Create Database Desktop Application

Create new  Database Desktop Application:
Click button to create a new application:
[精]Oracle APEX 5.0 新手教程(一) Form表单_第15张图片
Enter the name of the application:
  • Hello Database Desktop Application
[精]Oracle APEX 5.0 新手教程(一) Form表单_第16张图片
By default, Home page is created simultaneously with the application. You can add other pages into the application by clicking  "Add Page". It is best to add them later.
[精]Oracle APEX 5.0 新手教程(一) Form表单_第17张图片
[精]Oracle APEX 5.0 新手教程(一) Form表单_第18张图片
[精]Oracle APEX 5.0 新手教程(一) Form表单_第19张图片
[精]Oracle APEX 5.0 新手教程(一) Form表单_第20张图片
Your application has been created. Its ID is 115 and it has two  Login & Home pages.
[精]Oracle APEX 5.0 新手教程(一) Form表单_第21张图片
Currently, Home page has not been designed. However, you can click on the icon   to test the web.
[精]Oracle APEX 5.0 新手教程(一) Form表单_第22张图片

6.2- Create your first page

Next, we add a page displaying a list of departments (DEPT Table) and a page used to create and edit the information of departments. To be simple, we create this page in form of an available Template of  Oracle APEX. In the next part, I will instruct you to create a new page from a blank page so that you can thoroughly understand the issue.
Select   "Form on a Table with Report". To this template,  Oracle APEX will provide you with two pages which include a page of list of departments (DEPT) and a form of creating (and edit) information of departments.
[精]Oracle APEX 5.0 新手教程(一) Form表单_第23张图片
First,   Oracle APEX requires you to enter the information for the page containing the list of departments (DEPT). Page ID is an important attribute you have to remember. I grant 2 to ID of this page. (Note: Home page's ID is 1).
[精]Oracle APEX 5.0 新手教程(一) Form表单_第24张图片
Select DEPT table:
[精]Oracle APEX 5.0 新手教程(一) Form表单_第25张图片
Enter Menu:
  • New Navigation Menu Entry: Dept List (2)
[精]Oracle APEX 5.0 新手教程(一) Form表单_第26张图片
Choose columns to display:
[精]Oracle APEX 5.0 新手教程(一) Form表单_第27张图片
Next, enter the information of Form page. Here I grant 3 for Page ID.
Page Mode:
  • Normal: It means when you click on creating a new department, the web will move to a new page so that you can enter the information of the department.
  • Model Dialog: It means when you click on creating a new department, a Dialog will display  so that you can enter the information.
[精]Oracle APEX 5.0 新手教程(一) Form表单_第28张图片
Select Primary Key Column:
When you create a new DEPT record, DEPTNO column will be automatically granted for a value by DEPT_SEQ sequence.
[精]Oracle APEX 5.0 新手教程(一) Form表单_第29张图片
[精]Oracle APEX 5.0 新手教程(一) Form表单_第30张图片
[精]Oracle APEX 5.0 新手教程(一) Form表单_第31张图片
Two pages have been created. First, have a trial run.
[精]Oracle APEX 5.0 新手教程(一) Form表单_第32张图片
[精]Oracle APEX 5.0 新手教程(一) Form表单_第33张图片
[精]Oracle APEX 5.0 新手教程(一) Form表单_第34张图片
OK, everything is perfect. Return to design screen to discover what  Oracle APEX has created.
[精]Oracle APEX 5.0 新手教程(一) Form表单_第35张图片
Oracle APEX creates two pages in form of  "Interactive Report" and  "DML Form".
Click  "Form on DEPT (3)" to edit.
[精]Oracle APEX 5.0 新手教程(一) Form表单_第36张图片
[精]Oracle APEX 5.0 新手教程(一) Form表单_第37张图片
In the above illustrative image, you will see the design desktop is divided into three parts:
  1. Items of the page, including Regions, Buttons, and Processing.
  2. Interface of the page. A page usually has six regions:
    • PAGE HEADER
    • PAGE NAVIGATION
    • BREADCRUMB BAR
    • CONTENT BODY
    • FOOTER
    • INLINE DIALOGS
3. When you select a item of the page as mentioned in part 1, its attributes will display in part 3 (this region).
Example: You click on PAGE item,change the attribute of Page Mode into  "Model Dialog", and click on save as the following illustrative image:
[精]Oracle APEX 5.0 新手教程(一) Form表单_第38张图片
And rerun this page.
[精]Oracle APEX 5.0 新手教程(一) Form表单_第39张图片
A Dialog will be opened and it allows you to enter the information of a new department.
[精]Oracle APEX 5.0 新手教程(一) Form表单_第40张图片

6.3- Create a page from scratch

In the above parts, I introduced you how to quickly create a web with processing codes automatically created by   Oracle APEX. In order to understand   Oracle APEX much more, in this part, I will recreate the above example from scratch without using available templates of   Oracle APEX
This is the model of 2 pages I will create:
[精]Oracle APEX 5.0 新手教程(一) Form表单_第41张图片
  • Create Page
Select blank page:
[精]Oracle APEX 5.0 新手教程(一) Form表单_第42张图片
[精]Oracle APEX 5.0 新手教程(一) Form表单_第43张图片
Page list of departments (DEPT) will be put on the menu.
[精]Oracle APEX 5.0 新手教程(一) Form表单_第44张图片
[精]Oracle APEX 5.0 新手教程(一) Form表单_第45张图片
A blank page was created. We create the shown list of departments, this region will be included in  "Content Body" section.
A new region has been created:
[精]Oracle APEX 5.0 新手教程(一) Form表单_第46张图片
Enter information into the region you create:
  1. Title: Dept List
  2. Type: Interactive Report
  3. Source SQL Query: Select DEPTNO, DNAME, LOC from DEPT
  4. SAVE
Now you can press the RUN ( ), for testing
[精]Oracle APEX 5.0 新手教程(一) Form表单_第47张图片
You need to add a column that contains editing icons, as shown below:
[精]Oracle APEX 5.0 新手教程(一) Form表单_第48张图片
Choose Node Attributes in  "Dept List" section. And setting the properties as shown below:
[精]Oracle APEX 5.0 新手教程(一) Form表单_第49张图片
With:
  • Link Column = Link to Single Row View
That means that when you click on the icon view (modify) records, the application will jump to a default page (displays record information)

If you want to jump to his customizable page you can set up (which will be discussed later).
  • Link Column = Link to Custom Target
Rerun this page:
Web page will turn to a default page, and show information that you have selected.

Form

Next, we create a Form page, when you click to modify or create a department, it will turn to this page.
[精]Oracle APEX 5.0 新手教程(一) Form表单_第50张图片
[精]Oracle APEX 5.0 新手教程(一) Form表单_第51张图片
[精]Oracle APEX 5.0 新手教程(一) Form表单_第52张图片
[精]Oracle APEX 5.0 新手教程(一) Form表单_第53张图片
Một trang trắng đã được tạo ra, chúng ta sẽ tạo một vùng chứa form.
Enter informations for new creating region:
  • Title: Form on Dept
  • Type: Static Content
Note: With type of " Region Type = Static Content". You need to create Items in this region, and write display processing and handling (insert, update, delete) data to DB. 
We will create three fields:
  • Hidden: DEPTNO
  • Text Field: DNAME
  • Text Field: LOC
Drag and drop an Hidden item into ITEMS area as shown below:
[精]Oracle APEX 5.0 新手教程(一) Form表单_第54张图片
Setting properties for Item:
Similarly create 2 TEXT-FIELD:
[精]Oracle APEX 5.0 新手教程(一) Form表单_第55张图片
[精]Oracle APEX 5.0 新手教程(一) Form表单_第56张图片
Testting:
The user selects a record on list (page 4) to modify, it will be turned to Form page (page 5) and pass ID of record. You need to make a Process (On Pre-Rendering) on page 5 to load data and shown on Form:
Make a process in: 
  • Pre-Rendering/After Header
This process will be called before the page is shown. 
Enter:
  • Name: Fetch/load row From DEPT
  • Type: Automatic Row Fetch
  • Table Name: DEPT
  • Primary Key Column: DEPTNO
  • Primary Key Item: P5_DEPTNO
[精]Oracle APEX 5.0 新手教程(一) Form表单_第57张图片
Turn back page 4 ( Dept List (4)) for configuration transmits parameters from page 4 to page 5.
[精]Oracle APEX 5.0 新手教程(一) Form表单_第58张图片
[精]Oracle APEX 5.0 新手教程(一) Form表单_第59张图片
[精]Oracle APEX 5.0 新手教程(一) Form表单_第60张图片
Save and test page:
Next, we add new creating functions and Save record as shown below:
[精]Oracle APEX 5.0 新手教程(一) Form表单_第61张图片
On page 4:
[精]Oracle APEX 5.0 新手教程(一) Form表单_第62张图片
[精]Oracle APEX 5.0 新手教程(一) Form表单_第63张图片
[精]Oracle APEX 5.0 新手教程(一) Form表单_第64张图片
Next Jump to page 5.
Kéo thả các Button vào các vị trí trên màn hình thiết kế như hình minh họa dưới đây:
[精]Oracle APEX 5.0 新手教程(一) Form表单_第65张图片
When you click CANCEL on page 5, the website will go to page 4.
Setting properties for CANCEL button:
  • Button Name: CANCEL
  • Label: Cancel
  • Action: Redirect to Page in this Application
[精]Oracle APEX 5.0 新手教程(一) Form表单_第66张图片
[精]Oracle APEX 5.0 新手教程(一) Form表单_第67张图片
  • DELETE_IMMEDIATELY

When click button DELETE_IMMEDIATELY, record will be delete without prompting. We'll setting attributes for this button:
  • Button Name: DELETE_IMMEDIATELY
  • Label: Delete (Immediately)
  • Action: Submit Page
  • Database Action: SQL DELETE Action
This button will show up if the P5_DEPTNO not null:
  • Condition Type: Item not null
  • Condition Item: P5_DEPTNO
[精]Oracle APEX 5.0 新手教程(一) Form表单_第68张图片
  • DELETE_CONFIRM

When click this button, the application ask user whether want to delete this record or not. 
Set up attributes for  DELETE_CONFIRM button:
  • Button Name: DELETE_CONFIRM
  • Label: Delete (confirm)
  • Action: Redirect to URL
  • Target: javascript:apex.confirm('Are you sure?','DELETE_CONFIRM');
  • Database Action: SQL DELETE action
Condition for this button appear on page.
  • Condition Type: Item is NOT NULL
  • Condition Item: P5_DEPTNO
[精]Oracle APEX 5.0 新手教程(一) Form表单_第69张图片
Note:

apex.confirm (text, BUTTON_NAME)
 is an available javascript function on APEX, it will display a Dialog requires user confirm action before executing definition action on BUTTON_NAME.

This button will appear on web page when P5_DEPTNO is not null. 
You can also define a javacript variable and use it on whole web page.
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Declare a variable named htmldb_delete_message
var htmldb_delete_message= 'Would you like to perform this delete action?' ;
 
// Or:
// "DELETE_CONFIRM_MSG" is a constant available in APEX.
// It has value: Would you like to delete this thực action?
 
 
var htmldb_delete_message= '"DELETE_CONFIRM_MSG"' ;
 
 
// Then can use this variable in the whole page.
 
apex.confirm(htmldb_delete_message, 'DELETE_CONFIRM' );
  • SAVE_EDIT

This button will shown for user to modify available record on DB (make an Update order on DB).
  • Button Name: SAVE_EDIT
  • Label: Save (edit)
  • Action: Submit Page
  • Database Action: SQL UPDATE action
Condition for this button display on page. 
  • Condition Type: Item is NOT NULL
  • Condition Item: P5_DEPTNO
[精]Oracle APEX 5.0 新手教程(一) Form表单_第70张图片
  • SAVE_CREATE

  • Button Name: SAVE_CREATE
  • Label: Save (create)
  • Action: Submit Page
  • Database Action: SQL INSERT action
  • Condition
    • Type: Item is NULL
    • Item: P5_DEPTNO
[精]Oracle APEX 5.0 新手教程(一) Form表单_第71张图片
  • Process

Next, we add 3 Process:
  1. Get PK: Check P5_DEPTNO has assigned value or not, if not, we will assign the value for it from DEPT_SEQ (Use in case of Save Insert).
  2. Process Row of Dept: Execute actions (Insert, Update, or Delete).
  3. Reset Page: Delete statuses.
[精]Oracle APEX 5.0 新手教程(一) Form表单_第72张图片
Create a new process named " Get PK", and enter attribute values:
  • Name: Get PK
  • Type: PL/SQL Code
  • PL/SQL Code:
?
1
2
3
4
5
6
7
begin
     if :P5_DEPTNO is null then
         select DEPT_SEQ.nextval
           into :P5_DEPTNO
           from dual;
     end if;
end ;
[精]Oracle APEX 5.0 新手教程(一) Form表单_第73张图片
Next, you create the Processer " Process Row of DEPT" with attributes:
  • Name: Process Row of DEPT
  • Type: Automatic Row Processing (DML)
  • Table Name: DEPT
  • Primary Key Column: DEPTNO
  • Primary Key Item: P5_DEPTNO
  • Support Operations:
    • Insert
    • Update
    • Delete
[精]Oracle APEX 5.0 新手教程(一) Form表单_第74张图片
Next, you create process  "Reset page" and attribute configuration "Only used for deleting record" for it.

Conditions for this process to be executed is the request that contains word "DELETE", it means that it will be executed when you click DELETE_IMMIDIATELY or DELETE_CONFIRM button.
[精]Oracle APEX 5.0 新手教程(一) Form表单_第75张图片
After the process is completed (Insert, update, delete) on page 5, to turn back page 4, you need a processing in  "After Processing"
[精]Oracle APEX 5.0 新手教程(一) Form表单_第76张图片
[精]Oracle APEX 5.0 新手教程(一) Form表单_第77张图片
Now, You can Save the changes in design screen and try the application: 
[精]Oracle APEX 5.0 新手教程(一) Form表单_第78张图片

7- Oracle APEX Programming Tutorial (continue)

You can read more document:

你可能感兴趣的:(oracle,APEX)