Go to primary content
Oracle® Application Express Application Builder User's Guide
Release 5.0
E39147-04
  Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
 
Next
Next
 

11.4 Creating a Form Manually in Component View

This section describes how to create a form manually.

11.4.1 About Creating Forms Manually in Component View

You can also create a form manually by performing the following steps:

  • Step 1 - Create an HTML region (to serve as a container for your page items)

  • Step 2 - Create items to display in the region

  • Step 3 - Create processes and branches

To create a form manually by creating an HTML region:

  1. Navigate to the appropriate page. See "Viewing a Page in Component View".

  2. Create an HTML region. See "Creating a Region in Component View."

  3. Start adding items to the page. "Understanding Page-Level Items."

11.4.2 Processing a Form

Once you create a form, the next step is to process the data a user types by inserting into or updating the underlying database tables or views. This section describes three ways to process a form.

11.4.2.1 Creating an Automatic Row (DML) Processing Process

One common way to implement a form is to manually create an Automatic Row Processing (DML) process. This approach offers three advantages. First, you are not required to provide any SQL coding. Second, Oracle Application Express performs DML processing for you. Third, this process automatically performs lost update detection. Lost update detection ensures data integrity in applications where data can be accessed concurrently.

To implement this approach you must:

  • Add items, define the Item Source Type as Database Column, and specify a case-sensitive column name.

  • Select the option Always overrides the cache value.

To create an Automatic Row Processing (DML) process:

  1. Navigate to the appropriate page. See "Viewing a Page in Component View"

  2. Access the Create Page Process Wizard. Under Processes, click the Create icon.

  3. For Process Type, select Data Manipulation and click Next.

  4. Select the process category Automatic Row Processing (DML) and click Next.

  5. For Process Attributes:

    1. Name - Enter a name to identify the process.

    2. Sequence - Specify a sequence number.

    3. Point - Choose the point of execution for this process (for example, Onload - After Header).

    4. Type - Displays the selected process type.

    5. Click Next.

  6. Follow the on-screen instructions.

11.4.2.2 Creating a Process that Contains One or More Insert Statements

In this approach to form handling, you create one or more processes to handle insert, update, and delete actions. Instead of having the Application Express engine handling everything transparently, you are in complete control.

For example, suppose you have a form with three items:

  • P1_ID - A hidden item to store the primary key of the currently displayed row in a table.

  • P1_FIRST_NAME - A text field for user input.

  • P1_LAST_NAME - A text field for user input.

Assume also there are three buttons labeled Insert, Update, and Delete. Also assume you have a table T that contains the columns id, first_name, and last_name. The table has a trigger that automatically populates the ID column when there is no value supplied.

To process the insertion of a new row, you create a conditional process of type PL/SQL that executes when the user clicks the Insert button. For example:

BEGIN
  INSERT INTO T ( first_name, last_name )
     VALUES  (:P1_FIRST_NAME, :P1_LAST_NAME);
END; 

To process the updating of a row, you create another conditional process of type PL/SQL. For example:

BEGIN
    UPDATE T
       SET first_name = :P1_FIRST_NAME,
           last_name = :P1_LAST_NAME
    WHERE ID = :P1_ID;
END; 

To process the deletion of a row, you create a conditional process that executes when the user clicks the Delete button. For example:

BEGIN
    DELETE FROM T
    WHERE ID = :P1_ID;
END;

11.4.2.3 Using a PL/SQL API to Process Form Values

For certain types of applications, it is appropriate to centralize all access to tables in a single or a few PL/SQL packages. If you created a package to handle DML operations, you can call procedures and functions within this package from an After Submit PL/SQL process to process insert, updates, and delete requests.

11.4.3 Populating Forms in Component View

Oracle Application Express populates a form either on load or when the Application Express engine renders the page. You can populate a form in the following ways:

  • Create a process and define the type as Automated Row Fetch.

  • Populate the form manually by referencing a hidden session state item.

To create an Automated Row Fetch process:

  1. Navigate to the appropriate page. See "Viewing a Page in Component View".

  2. Access the Create Page Process Wizard. Under Processes, click the Create icon.

  3. For process type, select Data Manipulation and click Next.

  4. Select the process category, select Automatic Row Fetch and click Next.

  5. For Process Attributes:

    1. Name - Enter a name to identify the process.

    2. Sequence - Specify a sequence number.

    3. Point - Choose the point of execution for this process.

    4. Type - Displays the selected process type.

    5. Click Next.

  6. Follow the on-screen instructions.

You can also populate a form manually by referencing a hidden session state item. For example, the following code in an Oracle Application Express process of type PL/SQL would set the values of ename and sal. The example also demonstrates how to manually populate a form by referencing a hidden session state item named P2_ID.

FOR C1 in (SELECT ename, sal
FROM emp WHERE ID=:P2_ID)
LOOP     
     :P2_ENAME := C1.ename;
     :P2_SAL := C1.sal;
END LOOP;

In this example:

  • C1 is an implicit cursor.

  • The value of P2_ID has been set.

  • The process point for this process would be set to execute (or fire) on or before Onload - Before Regions.