X

Technical Articles relating to Oracle Development Tools and Frameworks

Prioritizing your messages

Duncan Mills
Architect

I've just uploaded a small sample onto the ADF EMG Samples site which demonstrates how you can make the <af:messages> component behave differently based on the messages that are in the queue.  The use case here was within a system where we wanted to use in-line messages for those run-of-th-mill type messages that should not really interrupt the flow of the user's activity (informational messages such as "Record Saved") , however, if something goes wrong then we wanted a popup to get in the users face, so to speak. 

The mode of display within the messages tag is controlled by the inline property, so in the sample application, rather than hardcoding this instead I evaluate an EL expression that returns a boolean.  Here's the code that implements the method I call:

public boolean isInlineMessage(){
boolean lowPriorityMessage = true;
  Iterator<FacesMessage> iter = FacesContext.getCurrentInstance().getMessages();
  while (iter.hasNext()){
  FacesMessage msg = iter.next();
    if (msg.getSeverity() == FacesMessage.SEVERITY_ERROR || 
msg.getSeverity() == FacesMessage.SEVERITY_FATAL){
    lowPriorityMessage = false;
      break;
    }
  }
return lowPriorityMessage;
}

In this code I simple iterate through the message stack and check to see if there are any messages at the ERROR or FATAL level. If that is the case I return false rather than true for the method result.

The only twist here is to ensure that your partialTriggers are set up correctly so that the <af:messages> tag is re-evaluated.

Anyway, the demo code is available here.  Enjoy.

Note: The demo will only run in 11.1.1.7  and 11.1.2..3 + but the message checking code part will run in earlier versions as well.  It's just that the demo screen uses the new panelGridLayout. 

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.