Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check in JSF EL what severity messages are shown

Tags:

jsf

el

jsf-2

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.

like image 613
alex Avatar asked Jan 13 '23 05:01

alex


1 Answers

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)

like image 131
BalusC Avatar answered Jan 22 '23 04:01

BalusC