Extend Your ApplicationsBy David Peake
Use plug-ins with Oracle Application Express 4.0 to add custom components.
Oracle Application Express 4.0 introduced a plug-in architecture that enables developers to extend their applications with custom item and region types, processes, and dynamic actions. Several plug-ins are free for downloading from Oracle Technology Network, and more than 40 plug-ins developed by members of the Oracle Application Express community are available from an external Website.
This column walks you through building an application that implements and uses three existing plug-ins. You can run through these steps on the hosted instance of Oracle Application Express 4.0 at apex.oracle.com. (You must request a free workspace to use this hosted instance.) You can also use a local instance of Oracle Application Express 4.0. This exercise is based on the EMP table, which is available by default in the database.
Modifying the EMP Table
You’ll build a database application that enables users to view and edit employee data. Before you create the application, you need to add two new columns to the EMP table and change some user interface defaults. Log in to Oracle Application Express, and follow these steps to add PHONE_NUMBER and RATING columns to the EMP table:
Now you’ll change some of the EMP table’s column labels to add some visual appeal to the demonstration application. With the EMP table still open in the Object Browser, follow these steps:
Repeat the preceding step to change the labels for the ENAME, MGR, HIREDATE, SAL, COMM, and DEPTNO columns to, respectively, Employee Name, Manager, Hire Date, Salary, Commission, and Department.
Creating the Demonstration Application
To create the demonstration application, follow these steps:
Next you’ll install two plug-ins into the Employees application that will help users input data easily into the application’s Phone Number and Rating fields. You’ll also install a plug-in that generates an employee organization chart and adds it to the application’s report page.
Downloading and Installing Plug-Ins
Download the following plug-ins from Oracle Technology Network at oracle.com/technetwork/developer-tools/apex/plugins-155231.html, and unzip them to a convenient location on your system:
Next, download and unzip the Google Visualizations plug-ins from apex-plugin.com, the community plug-in site. This set of dynamic-action, region-type plug-ins includes one that generates an organization chart from the EMP table.
To install the plug-ins, follow these steps:
Now you’ll replace standard Oracle Application Express components with the item-type plug-ins and define a plug-in region. To implement the item-type plug-ins, follow these steps:
To implement the region-type plug-in, follow these steps:
Click Examples. Copy the second block of SQL code, paste it into Region Source, and then click Create Region.
Click the Run button to run the application. You can see the organization chart, shown in Figure 1, at the bottom of the report page.
Figure 1: Organization chart generated by the Google OrgChart plug-in
In the tabular portion of the report page, click the edit link (the pencil icon) for the employee named Allen to modify his record. Click in the Phone Number field in the form, and enter a phone number (including area code) by typing its 10 digits. Note that the field will not accept any nonnumeric characters; the parentheses that surround the area code and the hyphen that separates the phone number’s first three digits from the last four are supplied by the plug-in. Now hover the cursor over the star icons in the Rating field and click the fourth icon from the left to give Allen a four-star rating. Figure 2 shows data being entered into the Phone Number field and a star being selected from the star icons.
Figure 2: Data entry assisted by plug-ins
Click Apply Changes. In the report, you can now see 4 as Allen’s rating, and the phone number you entered appears as Allen’s phone number.
Oracle Application Express plug-ins enable you to extend your applications easily with customizable components. Once you’ve imported and installed plug-ins, you use them in much the same way as you use standard Oracle Application Express components. You can choose among plug-ins developed by the Oracle Application Express team or the community. And you can build your own plug-ins by using PL/SQL. For information on building plug-ins, see Patrick Wolf’s blog posting “Oracle APEX 4.0: How to create a Plug-in”.
David Peake (email@example.com) is a principal product manager in Oracle’s Server Technologies division. He has been with Oracle since 1993.