DEVELOPER: Browser-BasedSingle-Step DeploymentBy Raj Mattamal Oracle Application Express deploys an application with a single file. With Oracle Application Express 2.2, when you build an application you want to share, you can create a single file that comprises the export—database objects, application components, and all. To demonstrate how simple it is to take advantage of this new convenience feature, this column walks you through the process of building a simple employee lookup application and then packaging up that application for single-step deployment. Step 1: Set Up the Table, Photo-Rendering Procedure, and Seed Data To get started, create (or have your Oracle Application Express administrator create) a new Oracle Application Express workspace. Once you've logged in to the workspace, run om_employees.sql to create the OM_EMPLOYEES table in your schema, along with its trigger and constraints. To run the script 1. Click SQL Workshop . Repeat steps 2 through 6, uploading and then running the om_download_pict.sql and seed_data.sql scripts (available in the o46browser.zip file). Step 2: Create the Application Now create a simple two-page application based on OM_EMPLOYEES: 1. Click the Application Builder tab. Step 3: Modify the Application to Allow Employees to Upload Photos The next step is to modify the two generated pages so that the application is read-only, while allowing users to upload photos to their respective detail pages. 1. In the listing of pages shown for the application, click the OM_EMPLOYEES link for page 1. (select userid from OM_EMPLOYEES ome2 where ome2.employee_id = ome.manager_id) 4. Add a column alias Manager to the inline query above, so it can serve as a column heading in the resulting report. Listing 1 shows an excerpt of the relevant code (in bold) for the modified query to add to the Region Source text box. Code Listing 1: _Modified query select "EMPLOYEE_ID", "NAME_FIRST", "NAME_LAST", "TITLE", "EMAIL", "PHONE_OFFICE", "PHONE_MOBILE", "STREET_ADDRESS", "CITY", "STATE", "ZIP_CODE", "HIRE_DATE", "USERID", (select userid from OM_EMPLOYEES ome2 where ome2.employee_id=ome.manager_id) "Manager", "MIME_TYPE", "BLOB_CONTENT" from "OM_EMPLOYEES" OME where . . . <snip> 5. Click the Report Attributes tab. Make page 2 read-only. Enter 2 in the Page field, and click Go to navigate to page 2 of the application. 1. In the Buttons section, click the Create link and then click Delete to delete page 2's Create button. Confirm the deletion when prompted. select userid, employee_id from om_employees 9. Click the right arrow to navigate to the next item (P2_MIME_TYPE). Modify page 2 to support photo display. The application should display a photo only if one is actually stored in the table. If there's no photo stored, and the userid in the table matches that of the logged-in user, the page should display an Upload button. To provide these capabilities, make these changes to the P2_BLOB_CONTENT item: 1. Click the Label navigation button, and enter Photo in the Label field.
htf.img ('#OWNER#.om_download_pict?
p_id='||:P2_EMPLOYEE_ID)
4. Click the Conditions navigation button, and for the condition type, select Exists (SQL Query returns at least one row) .
select 1 from OM_EMPLOYEES where :P2_EMPLOYEE_ID
= employee_id and blob_content is not null
6. Click Apply Changes . Add an item for the photo. Next, the application must provide a means for users to upload their photos: 1. Click the Create icon in the Items section of the page 2 definition screen.
select 1 from OM_EMPLOYEES where :P2_EMPLOYEE_ID =
employee_id and userid = :APP_USER and blob_content is null
7. Click Apply Changes . Modify other page 2 UI components for photo handling. Just a few more steps to complete the application: 1. In the Buttons section of page 2's definition, click the Apply Changes link to edit the SAVE button's properties.
select 1 from OM_EMPLOYEES where :P2_EMPLOYEE_ID =
employee_id and userid = :APP_USER and blob_content is null
4. Click Apply Changes . Code Listing 2: _Condition text for photo upload IF ( :P2_PHOTO is not null ) THEN update OM_EMPLOYEES e set (blob_content, mime_type) = ( select blob_content, mime_type from htmldb_application_files where name = :P2_PHOTO) where employee_id = :P2_EMPLOYEE_ID; DELETE from HTMLDB_APPLICATION_FILES WHERE name = :P2_PHOTO; END IF; 13. Click Next and Create Process to finish creating the Store Photo process. At this point, you should have a functional employee lookup application. Run the application, and you'll see that you can search for employees and view detail information about them. Create an Oracle Application Express user account to match one of the userids in the OM_EMPLOYEES table and log in to the application using that account, and you'll see the photo upload capability and display. Step 4: Package Up the Application After you try out the application, you might decide that others might find it useful enough to install in their own Oracle Application Express instances. To this end, the last step is packaging up the application for single-step deployment to another instance. 1. In the breadcrumb links in the upper left-hand corner of the screen, click the Application nnn link (where nnn corresponds to the ID of the employee lookup application in your Oracle Application Express instance).
5. Click the right arrow to go to the Prerequisites tab. 6. To ensure that folks who already have a table named OM_EMPLOYEES in their schemas don't run into a conflict with this script, enter OM_EMPLOYEES in the first Object Names field and click Add. 7. Click the Scripts tab. 8. Click Create . 9. Click the Copy from SQL Script Repository icon. 10. Enter Create Table, Sequence, and Trigger in the Name field, and click Next . 11. Select om_employees.sql , and click Create Script . 12. Repeat steps 9 through 11 for the om_download_pict.sql and seed_data .sql scripts. Feel free to name these scripts as you see fit. 13. Click the Deinstall tab, and click Create . 14. Click the Create from File icon. 15. Click Browse , select the drop_om_objects.sql script (included with this column's download file), click Open , and click Create Script . 16. Click the right arrow. 17. Select Yes for Include Supporting Object Definitions in Export . 18. Click Apply Changes . And that's it. Now when you export this application, everything comes with it: the DDL, the seed data, and the Oracle Application Express application definition. To move the application to another Oracle Application Express 2.2 instance, simply import and install the single export file. |
