I want to know what kind of messages are shown in the current page using EL. I'm particularly interested in errors above warning severity. My current solution is this:
#{ facesContext.getMaximumSeverity().getOrdinal() ge 2}
But i want a better one (safer and more explicit), something like this:
#{facesContext.getMaximumSeverity() != null and facesContext.getMaximumSeverity().compareTo(facesMessage.SEVERITY_WARN)>0}
The problem is that i can't get any value out of facesMessage.SEVERITY_WARN. Can someone help me with this? Thanks.
Until the upcoming EL 3.0, you can't reference constants in EL.
As to open source libraries, the only one which can help you in this is OmniFaces. It offers a <o:importConstants>
tag for the very purpose.
<o:importConstants type="javax.faces.application.FacesMessage" />
This way you'll be able to use
#{facesContext.maximumSeverity eq FacesMessage.SEVERITY_ERROR or facesContext.maximumSeverity eq FacesMessage.SEVERITY_FATAL}
or
#{facesContext.maximumSeverity.compareTo(FacesMessage.SEVERITY_WARN) gt 0}
or
#{facesContext.maximumSeverity.compareTo(FacesMessage.SEVERITY_ERROR) ge 0}
or
#{facesContext.maximumSeverity.ordinal gt FacesMessage.SEVERITY_WARN.ordinal}
or
#{facesContext.maximumSeverity.ordinal ge FacesMessage.SEVERITY_ERROR.ordinal}
(note that I omitted the unnecessary get
prefix and ()
parens, IDE-autocomplete in EL doesn't necessarily generate right and clean code)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With