In this column, you’ll build an application that uses dynamic actions to implement Ajax behavior. 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 uses the EMP and DEPT tables, which are available by default in the database.Creating the Demonstration Application Start by creating a database application that enables users to view and edit employee data. Log in to Oracle Application Express and follow these steps to create the demonstration application:
Now enhance the form you’ve just generated to include select lists for job and department. The following steps and subsequent instructions assume that you are using the tree view, not the component view, in Application Builder:
By defining these user-interface defaults for the application’s tables before generating pages, you give the tables consistent column attributes such as headings, the display format (including a list of values), and the display sequence.
Click Run and log in with your Oracle Application Express credentials to run the application. Navigate back to the report by clicking the first Emp link in the breadcrumbs. You can edit any record by clicking its Edit icon.Defining a Standard Dynamic Action Now create a dynamic action that will enable the form’s commission field (called Comm) only for employees whose job title is salesman. Follow these steps:
Run the application, and edit the record of an employee with any job other than salesman. In the form, you can see that the Comm field is disabled. To enable the Comm field, change the Job field’s value to SALESMAN.Defining an Advanced Dynamic Action Now modify the Employee application to retrieve a department’s location as soon as the Department field is updated. The application will use Ajax to retrieve the value asynchronously without needing to submit the entire page to the server.
To create the advanced dynamic action, follow these steps:
Figure 1: Creating a page item
As you can see in Figure 2, you can choose among many types of events when you implement an advanced dynamic action. Select Change (the default). Leave the Condition field value as - No Condition -, because you want the change event to always fire.
Figure 2: Selecting the event type for a dynamic action
Now when you run the application and change the value for any employee’s department, you’ll see that the location is updated immediately, as shown in Figure 3.
Figure 3: Change the department, see the result
LEARN more about
Photography byLuke Ellis-Craven,Unsplash