Tutorial 9: How to build an alert

This tutorial explains how to build an alert in a Formspider Application. It continues from the “Regions” application built in the “How to save changes to the database“.

In this tutorial you will add an alert to the “Regions” application. You will show this alert when “Delete Region” button is clicked. The purpose of this alert will be a confirmation request from the user before completing delete operation. By evaluating the response returned by your alert you will execute user’s decision.

As the first step, you will create the alert. To achieve this, expand the “Miscellaneous” accordion Panel, select the “Alerts” root node and click the “+” button from the toolbar of the accordion Panel. Alternatively, you may right click the “Alerts” root node in the Navigation Tree and click the “New” menu item from the pop up menu that is displayed. The “New Alert” dialog shows up.

Creating a new alert.

Enter “deleteRegionAlert” in the name section, you will use this name later on in PL/SQL API calls.

Label section is message which will be displayed to user when your alert is shown, enter “Are you sure you want to delete this region?” in this section.

You will use Button1 Label, Button2 Label and Button3 Label sections to label buttons which will be shown on the alert. As you notice, an alert can contain a maximum of three buttons in Formspider. Only buttons which were labeled will be displayed on the alert. For the purposes of this tutorial you will display two buttons; the infamous “OK” and “Cancel” pair. So, all you need to do is simply enter “OK” in the Button1 Label field and “Cancel” in the Button2 Label field.

Enter “Delete Region” as the alert title, it’s the title of your alert dialog.

Choose “Warning” option from the Icon combobox. There are four types of icons that you can use in an alertInfoWarningQuestion and Error.

Finally, On close is the section where you can specify which Formspider action will be fired when any of the alert buttons is clicked by the user. Leave it blank for now, you will create this action as the next step of this tutorial. Click “OK” to create your alert.

Creating "deleteRegionAlert".

As the next step, you have to show the alert when “Delete Region” button is clicked. To achieve this you will use “api_alert.show” PL/SQL API. Open the “regions_pkg” package and edit the “deleteRegion” procedure, remember that this procedure was created in “How to delete a row” tutorial and it’s called when “Delete Region” button is clicked.

procedure deleteRegion is
begin
  api_alert.show('deleteRegionAlert');
end;

Now, run your application and click “Delete Region” button; you will see that “deleteRegionAlert” will be shown.

Showing "deleteRegionAlert"

Notice that your alert is closing when you click either “OK” or “Cancel” alert button. Nothing happens more at this stage since you didn’t defined yet the action which will be fired when youralert is about closing, you will create this action as the last step of this tutorial.

Open the “regions_pkg” package in your favorite PL/SQL Editor and add a procedure named “deleteRegionAlert_Close” which calls the “api_alert.getresponse” to distinguish which alert button is clicked. The delete operation should be completed if “OK” button is clicked on the alert. So, by checking if clicked button in your alert is the Button1 (note that you labeled Button1 of your alert as “OK”) you may safely delete the row. Ensure that the procedure is exposed in the package specification.

procedure deleteRegionAlert_Close is
  v_alertResult_nr number;
begin
  v_alertResult_nr := api_alert.getresponse('deleteRegionAlert');
  if v_alertResult_nr = api_alert.button1 then
    api_datasource.deleteCurrentRow('REGIONS1');
  end if;
end;

Next, in Formspider IDE, create an action named “deleteRegionAlert_Close” that calls the “regions_pkg.deleteRegionAlert_Close” procedure.

Creating "deleteRegionAlert_Close" action

After creating your action, open “deleteRegionAlert” for edit. To achieve this, expand the “Alerts” root node and then select the “deleteRegionAlert” node. Click the edit button from the toolbar of the accordion panel. Alternatively, you may directly double-click the “deleteRegionAlert” or right-click the same node and select “Edit” menu item from the pop up menu that is displayed. The edit dialogshows up.

Editing "deleteRegionAlert" alert.

In the On Close combo box, choose your newly created “deleteRegionAlert_Close” action and click “OK” to save your changes.

That’s all. Run your application and click “Delete Region” button, “deleteRegionAlert” will be displayed. If you click “OK” this time, you will see that the currently selected row in the grid will be deleted.