JSF using EL to test global messages presence

Viewed 14241

I'm trying to display a block only if there are Global messages in the JSF Queue.

I tried to use rendered="#{not empty facesContext.getMessageList(null)}", but it's always evaluated to false.

Only way I found is to create a custom EL function and test it in java.

eg. : my el function :

public static boolean isFacesGlobalMessages() {
  return ! FacesContext.getCurrentInstance().getMessageList(null).isEmpty();
}

JSF page :

<h:panelGroup class="block1" layout="block" rendered="#{el:isFacesGlobalMessages()}">
  <div class="block-warn-body">
    <rich:messages id="msg" globalOnly="true"/>
  </div>
</h:panelGroup>

I'm using Mojarra 2.1.5.

Am I missing something ? Thanks !

Edit : tried the following suggestions, but no luck so far :

  • #{not empty facesContext.getMessageList(null)} -> always false
  • #{! facesContext.getMessageList(null)} -> error
  • #{! empty facesContext.getMessageList(null)} -> always false
  • #{fn:length(facesContext.getMessageList(null)) > 0} -> always false
  • #{not empty facesContext.messageList(null)} -> Error : Method messageList not found
  • #{not empty facesContext.messageList} -> returns true if it's a validation error (I only want true on global error)
  • #{! facesContext.getMessageList(null).isEmpty()} -> throws IllegalAccessException: Class javax.el.BeanELResolver can not access a member of class java.util.Collections$UnmodifiableCollection with modifiers "public"
3 Answers
Related