Check JSF EL for Severity Messages

I want to know which messages are displayed on the current page using EL. I am particularly interested in errors above the severity of the warning. My current solution is this:

#{ facesContext.getMaximumSeverity().getOrdinal() ge 2} 

But I want a better (safer and more explicit), something like this:

 #{facesContext.getMaximumSeverity() != null and facesContext.getMaximumSeverity().compareTo(facesMessage.SEVERITY_WARN)>0} 

The problem is that I cannot get any value from facesMessage.SEVERITY_WARN. Can someone help me with this? Thanks.

+4
source share
1 answer

Until the upcoming EL 3.0, you cannot reference constants in EL.

Regarding open source libraries, the only thing that can help you is OmniFaces . It offers a <o:importConstants> tag for the purpose itself.

 <o:importConstants type="javax.faces.application.FacesMessage" /> 

This way you can 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 skipped the unnecessary get and () parens prefix, IDE autocomplete in EL does not necessarily generate correct and clean code)

+7
source

Source: https://habr.com/ru/post/1483775/


All Articles