Introduction:
Oracle APEX (Application Express) is a robust platform that simplifies web application development. One key aspect of building user-friendly applications is providing clear and immediate feedback. Success messages, in particular, are crucial for informing users about the successful completion of actions such as form submissions or data updates. In Oracle APEX, managing these success messages effectively can enhance the user experience significantly. This blog will guide you through the process of using dynamic actions to handle success messages in Oracle APEX, ensuring you can provide timely and relevant feedback to users.
Why we need to do :
Consider a scenario where you are developing an Oracle APEX application for managing a customer database. Users interact with various forms to add, update, or delete customer records. It’s essential to provide feedback to users on the status of their actions:
- Form Submission: After submitting a form to add or update customer details, users should receive a success message indicating the operation was successful.
- Record Deletion: When users delete a customer record, they should see a confirmation dialog to avoid accidental deletions and a success message if the deletion is confirmed.
Handling these success messages effectively involves using dynamic actions in Oracle APEX to display and manage feedback messages. Let’s dive into a step-by-step guide on implementing these dynamic actions.
How do we solve :
Setting Up Dynamic Action for Success Message
To display a page-level success message using dynamic actions, follow these steps:
Create a Dynamic Action
Open your Oracle APEX application and navigate to the page where you want to add the success message.
Click on “Dynamic Actions” in the Page Designer to create a new dynamic action.
Define the Event
Select an Event that triggers the success message. For example, you might choose a “Submit” button or an “After Refresh” event of a report.
Configure the True Action
Add a True Action to execute JavaScript code.
In the JavaScript Code section, use the apex.message.showPageSuccess function to display a success message.
Example Code:
javascript
apex.message.showPageSuccess(“The record has been successfully updated!”);
Save the dynamic action and test it by performing the action that triggers the dynamic action. You should see the success message displayed on the page.
Hiding the Success Message
Sometimes, you may want to hide the success message programmatically. To do this:
Create Another Dynamic Action
Create a new dynamic action or edit an existing one where you want to hide the success message.
Define the Event
Select an appropriate event, such as navigating away from the page or starting a new operation.
Configure the True Action
Add a True Action to execute JavaScript code.
Use the apex.message.hidePageSuccess function to hide the message.
Example Code:
javascript
apex.message.hidePageSuccess();
Save the dynamic action and test to ensure the success message is hidden as expected.
Displaying Alerts with apex.message.alert
In addition to success messages, you might want to use alerts for immediate user feedback. Here’s how you can display an alert:
Create a Dynamic Action
Create or edit a dynamic action where you want to display the alert.
Define the Event
Choose an event that will trigger the alert.
Configure the True Action
Add a True Action to execute JavaScript code.
Use the apex.message.alert function to display an alert.
Basic Example:
javascript
apex.message.alert(“The operation is complete.”, function(){
console.log(“Alert dialog closed”);
});
Advanced Example with Custom Options:
javascript
apex.message.alert(“The operation is complete.”, function(){
console.log(“Alert dialog closed”);
}, {
title: “Update”,
style: “information”,
iconClasses: “fa fa-info fa-2x”,
okLabel: “Okay”
});
Save the dynamic action and test to see the alert in action.
Using Confirmation Dialogs with apex.message.confirm
For actions requiring user confirmation, such as deleting a record, use the apex.message.confirm function:
Create a Dynamic Action
Create or edit a dynamic action where a confirmation dialog is needed.
Define the Event
Choose an event that will trigger the confirmation dialog.
Configure the True Action
Add a True Action to execute JavaScript code.
Use the apex.message.confirm function to display the confirmation dialog.
Basic Example:
javascript
apex.message.confirm(“Are you sure you want to delete this item?”, function(okPressed) {
if (okPressed) {
console.log(“Item deleted”);
} else {
console.log(“Action cancelled”);
}
});
Advanced Example with Custom Options:
javascript
apex.message.confirm(“Are you sure you wish to delete this record?”, function(okPressed) {
if (okPressed) {
console.log(“Record deleted”);
} else {
console.log(“Action cancelled”);
}
}, {
title: “Warning!”,
style: “danger”,
iconClasses: “fa fa-trash fa-2x”,
cancelLabel: “No”,
confirmLabel: “I’m sure”
});
Save the dynamic action and test to ensure the confirmation dialog works as expected.
Conclusion :
Handling success messages and alerts effectively is crucial for providing a smooth user experience in Oracle APEX applications. By using dynamic actions and Oracle APEX’s JavaScript API functions such as apex.message.showPageSuccess, apex.message.hidePageSuccess, apex.message.alert, and apex.message.confirm, you can ensure that users receive timely and appropriate feedback on their actions.
These tools not only help in communicating the status of operations but also improve overall user satisfaction by making interactions more intuitive and responsive. Implement these techniques in your Oracle APEX projects to create a more engaging and user-friendly application experience.