Extending Your Application Using Plug-ins in Oracle Application Express 4.0

Purpose

This tutorial shows you how to use and built plug-ins in Oracle Application Express 4.0.

Time to Complete

Approximately 60 minutes.

Overview

What are Plugins?

Plug-ins enable developers to enhance the existing built-in functionality with new item types, region types, process types and dynamic actions to enhance and customize their application.

In this tutorial, you import the Star Rating Plug-in and then add it to your page as shown below.

starrating

In addition, you create a Masked Text Field Plug-in from scratch and then use it for your Phone Number item as shown below.

maskedtext

Prerequisites

Before starting this tutorial, you should:

Creating a Database Application

You want to create a new database application that will demonstrate the plug-in functionality.. Perform the following steps:

1 .

Enter the following URL in your browser to log in to Oracle Application Express.

http://<yourhostname>:8080/apex

 

2 .

To log in to Oracle Application Express, enter the following details, and click Login.

Workspace: <your workspace name>
Username: <your username>
Password: <your password>

Show Screenshot for Step

 

3 .

Select Application Builder > Database Applications.

Show Screenshot for Step

 

4 .

Click Create.

Show Screenshot for Step

 

5 .

Make sure the Database Application Type is selected and click Next.

Show Screenshot for Step

 

6 .

Make sure From Scratch is selected and click Next.

Show Screenshot for Step


7 .

Enter Plug-in Application for Name and click Next.

Show Screenshot for Step

 

8 .

Enter Home for Page Name and click Add Page.

Show Screenshot for Step

 

9 .

Select the Report and Form Page Type, select Home (1) for Subordinate to Page, enter DEMO_PRODUCT INFO or select it from the list of tables and click Add Page.

Show Screenshot for Step

 

10 .

Click Create to accept the default values for the rest of the wizard pages.

Show Screenshot for Step

 

11 .

Click Create to confirm.

Show Screenshot for Step

 

12 .

Your application was created successfully. Click Run Application.

Show Screenshot for Step

 

13 .

Enter obe for Username and Password and click Login.

Show Screenshot for Step

 

14 .

The Home page is displayed. Select the Demo Product Info link.

Show Screenshot for Step

 

15 .

The report is displayed. Select the edit icon for one of the products.

Show Screenshot for Step

 

16 .

The Product Form is displayed. You want to add a rating for the product. In the next topic you add the column to the table. Click the Home link in the developer toolbar.

Show Screenshot for Step

 

Adding a Column to Your Table

You will add a Star Rating Plugin to your page. You want to store the rating selected so you need to add a column to the table where you want to store the value. Perform the following steps:

1 .

Select SQL Workshop > Object Browser.

Show Screenshot for Step

 

2 .

Enter demo in the search area and select the DEMO_PRODUCT_INFO table in the list.

Show Screenshot for Step

 

3 .

Select Add Column.

Show Screenshot for Step


4 .

Enter RATING for Add Column, make sure NUMBER is selected for Type, enter 2 for Precision and click Next.

Show Screenshot for Step

 

5 .

Click Finish.

Show Screenshot for Step

 

6 .

The rating column was added successfully. Now you are ready to import the plug-in you will use in your application.

Show Screenshot for Step

 

Importing the Star Rating Plug-in to Use in Your Application

In order to use a plugin, you either need to create your plugin or import one from the repository or an export file. In this section you will import a file that contains the plug for a star rating. Perform the following steps:

1 .

Select Application Builder > Database Applications.

Show Screenshot for Step

 

2 .

Select your Plug-in Application.

Show Screenshot for Step

 

3 .

Select Shared Components.

Show Screenshot for Step

 

4 .

Under User Interface, select Plug-ins.

Show Screenshot for Step

 

5 .

There are currently no plug-ins. You will import the Star Rating plug-in which has been supplied in your files directory. Click Import.

Show Screenshot for Step

 

6 .

Click Browse...

Show Screenshot for Step

 

7 .

Select the item_type_plugin_com_oracle_star_rating.sql file from the directory where your files for this tutorial are located and click Open. Click Next.

Show Screenshot for Step

 

8 .

Click Next.

Show Screenshot for Step

 

9 .

Make sure your Plug-in Application is selected for Install into Application and click Install Plug-in.

Show Screenshot for Step

In the next section, you will add the plugin to your page.

 

Adding a Star Rating Plugin Item to Your Page

You want to add a rating item to the Product form page in your Plug-in Application. Perform the following steps:

1 .

Click the Application <n> breadcrumb.

Show Screenshot for Step

 

2 .

Select the 3-Demo Product Info form icon.

Show Screenshot for Step

 

3 .

Under the Edit DEMO_PRODUCT_INFO Region, right-click Items and select Create Page Item.

Show Screenshot for Step

 

4 .

Select the Item Type Plug-ins and click Next. Note that if there are no plug-ins contained under Shared Components > Plug-ins then this Item Type will not be shown on this page.

Show Screenshot for Step

 

5 .

Select the Star Rating radio button and click Next. Note that only the Plug-ins that have been imported for this application are displayed.

Show Screenshot for Step

 

6 .

Enter P3_RATING for Item Name and click Next.

Show Screenshot for Step

 

7 .

Accept the defaults and click Next.

Show Screenshot for Step

 

8 .

Accept the default to have 5 # of stars for the Rating and click Next.

Show Screenshot for Step

 

9 .

Select Database Column for Source Type, enter RATING for Database Column Name and click Create Item.

Show Screenshot for Step

 

10 .

The Rating item was created successfully. Click Run.

Show Screenshot for Step

 

11 .

The Star Rating item is displayed. When you put your cursor over one of the stars you see the stars change colors. Select the number of stars you want.

Show Screenshot for Step

 

12 .

Click Apply Changes.

Show Screenshot for Step

 

13 .

Your Star Rating was added to the database. In the next section, you will create a plug-in from scratch and then use it in your application. Select Application <n> in the developer toolbar.

Show Screenshot for Step

 

Adding a Masked Text Field Plugin

You may at some point want to create a plug-in to perform a function that is not currently available in Oracle Application Express. In this section you will create a item plug-in that allows a user to enter a fixed width input and enter data in a certain format such as a phone number. Perform the following steps:

1 .

Select the Shared Components icon.

Show Screenshot for Step

 

2 .

Under User Interface, select Plug-ins.

Show Screenshot for Step

 

3 .

You want to create a new plug-in. Click Create.

Show Screenshot for Step

 

4 .

Enter Masked Text Field for Name, COM.ORACLE.APEX.MASKED_TEXT_FIELD for Internal Name, make sure Item is selected for Type and click Create. Note that the internal name should be changed to your own domain name but for this example, you will use ORACLE.

Show Screenshot for Step

 

5 .

You need to add a file that contains the javascript needed for this plug-in. Select the Files subtab.

Show Screenshot for Step

 

6 .

Click Upload New File.

Show Screenshot for Step

 

7 .

Click Browse...

Show Screenshot for Step

 

8 .

Select the jquery.maskedinput-1.2.2.min.js file from the directory where your files for this tutorial are located and click Open. Then click Upload.

Show Screenshot for Step

 

9 .

Your file was added. Click the Custom Attributes tab.

Show Screenshot for Step

 

10 .

Click Add Attribute.

Show Screenshot for Step

 

11 .

Enter the following and click Create and Create Another.

Field Value
Label Mask
Required Yes
Display Width 40
Maximum Width 40
Default Value (999) 999-9999

Show Screenshot for Step

 

12 .

Enter the following and click Create.

Field Value
Label Placeholder
Required Yes
Display Width 1
Maximum Width 1
Default Value _

Show Screenshot for Step

 

13 .

You need to specify the code that will execute for this plug-in. Click the Source subtab.

Show Screenshot for Step

 

14 .

Copy and paste the code in the mask_plugin.txt file into the PL/SQL Code field and then click the Callbacks subtab.

Show Screenshot for Step

 

15 .

Make sure render_mask is set for Render Function Name and validate_mask is set for Validation Function Name and click Apply Changes.

Show Screenshot for Step

 

16 .

The Masked Text Field plug-in was created successfully. Now you want to create a new page where you can apply the plug-in. Click the Application <n> breadcrumb.

Show Screenshot for Step

 

Adding a Customers Form to Your Application

You will create 2 new pages (Report and Form) to maintain Customer information. Perform the following steps:

1 .

Click Create Page.

Show Screenshot for Step

 

2 .

Select Form and click Next.

Show Screenshot for Step

 

3 .

Select Form on a Table with Report and click Next.

Show Screenshot for Step

 

4 .

Accept the default and click Next.

Show Screenshot for Step

 

5 .

Enter DEMO_CUSTOMERS for Table/View Name and click Next.

Show Screenshot for Step

 

6 .

Enter Customer List for Page Name and Region Title, select Breadcrumb for Breadcrump, select Home for the Parent Entry and click Next.

Show Screenshot for Step

 

7 .

Accept the default and click Next.

Show Screenshot for Step

 

8 .

Shift+select CUST_FIRST_NAME, CUST_LAST_NAME and CUST_EMAIL and click Next.

Show Screenshot for Step

 

9 .

Accept the default and click Next.

Show Screenshot for Step

 

10 .

Enter Maintain Customers for Page Name, Region Title and Entry Name and click Next.

Show Screenshot for Step

 

11 .

Accept the default and click Next.

Show Screenshot for Step

 

12 .

Accept the default and click Next.

Show Screenshot for Step

 

13 .

Shift+select all the columns and click Next.

Show Screenshot for Step

 

14 .

Accept the default and click Next.

Show Screenshot for Step

 

15 .

Click Finish.

Show Screenshot for Step

 

16 .

Click Run Page.

Show Screenshot for Step

 

17 .

The report is displayed. Select the edit icon in front of one row.

Show Screenshot for Step

 

18 .

The form is displayed. Notice that Phone Number 1 is formatted however this number is not based on the plug-in. Change the number to something else.

Show Screenshot for Step

 

19 .

After you make your change, click Apply Changes to see that it was accepted..

Show Screenshot for Step

 

20 .

Click the edit icon again.

Show Screenshot for Step

 

21 .

Your change was accepted because there is no validation and the plug-in was not applied. In the next topic, you apply the Masked Text Plug-in to the Phone Number 1 item. Select the Edit Page link in the developer toolbar.

Show Screenshot for Step

 

Using the Masked Text Field Plugin in Your Page

Now that your masked text field plugin is imported and your customer form is created, you can use it for the Phone Number 1 item. Perform the following steps:

1 .

Right click P5_PHONE_NUMBER1 and select Edit.

Show Screenshot for Step

 

2 .

Select Masked Text Field [Plug-in] for Display As.

Show Screenshot for Step

 

3 .

Notice the Settings area is displayed which contains the Custom Attributes you specified when you created the plug-in. Accept the defaults and click Apply Changes.

Show Screenshot for Step

 

4 .

Click Run.

Show Screenshot for Step

 

5 .

The form is displayed. Notice the phone number looks the same as it did before. Delete the current contents of that field.

Show Screenshot for Step

 

6 .

Notice that the format of the field is displayed with the placeholder of a '_'. Change the '_' with a different number.

Show Screenshot for Step

 

7 .

The numbers for Phone Number are displayed in the format specified by the plug-in. Enter something in the Alt Phone Number field. Notice that the numbers do not have the same format applied. This is because this item is still a text item and the plug-in has not been applied.

Show Screenshot for Step

 

Summary

In this tutorial, you have learned how to:

Hardware and Software Engineered to Work Together About Oracle |Oracle and Sun | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Your Privacy Rights