Skip to Main Content

Handling Client-Side Messages in APEX 5.1

This page is sample page about using new APEX 5.1 apex.message namespace

Examples are made in APEX 5.1.0.00.43 which is currently available only on apex.oracle.com

Below, you can find examples of how to:

  • Show Success Message
  • Hide Success Message
  • Display Alert Message
  • Display Confirm Message
  • Display Error Messages

This page is a part of a blog post available on apexbyg.blogspot.com

Function to display success message. You have to pass message as parameter:
apex.message.showPageSuccess("Success Message");

Function to close success message box:
apex.message.hidePageSuccess();

Function for calling APEX alert message. You can pass two parameters:
@param {string} pMessage message to display
@param {function} [pCallback] function called when the dialog is closed. callback()
Callback function is optional parameter.

There are some important differences between APEX alert and build-in browser function:
  • The call to apex.message.alert does not block JS execution. Code following the call will run before the user presses OK.
  • Code to run after the user closes the dialog must be put in the callback.


You can change label of OK button by defining APEX.DIALOG.OK Text Message under Shared Components.
apex.message.alert('My Alert Message'
                 , function(){
                     alert("You've pressed ok! ");
                   }
);

Function for calling APEX confirm dialog. You can pass two parameters:
@param {string} pMessage message to display
@param {function} [pCallback] function called when the dialog is closed. callback()
Callback function is called with parameter true if you press Ok and false otherwise.

There are some important differences between APEX alert and build-in browser function:
  • The call to apex.message.confirm does not block JS execution and does not return true or false
  • Code following the call will run before the user presses OK or cancel. Acting on the users choice must be done from within the callback.


You can change label of OK button by defining APEX.DIALOG.OK Text Message under Shared Components (for cancel button you have to define APEX.DIALOG.CANCEL message).
apex.message.confirm('My Confirm Message'
     , function(result){
                     if(result===true){
                       alert("You've pressed Ok! ");
                     }else{
                       alert("You've pressed Cancel! "); 
                     }
                   }            
);

You can also display error messages (from the stack) but remember to call apex.message.clearErrors() before to clear the stack.
There's one input parameter:
@param {Array | Object} pErrors Error object, or an array of error objects to add to the error stack. Object in the following format:
[
  {
    "type":     "error",
    "location": "page",
    "message":  "Page error has occurred!"
  }
,{
    "type":     "error",
    "location": ["inline","page"],
    "pageItem": "P13_ENAME",
    "message":  "Ename is required!",
    "unsafe":   false   // if unsafe : true, then we escape it here, else false
  }
]

Sample code:
apex.message.clearErrors();
apex.message.showErrors(
[{
  "type":     "error",
  "location": ["inline","page"],
  "pageItem": "P13_ENAME",
  "message":  "Ename is required!",
  "unsafe":   false 
},
{
  "type":     "error",
  "location": "page",
  "message":  "Page error has occurred!"
}]
)
***Note: When you clich button Show Errors they are displayed on top of the page, so you need to scroll up.