Check in JSF EL what severity messages are shown

前端 未结 1 1751
难免孤独
难免孤独 2020-12-18 08:39

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:

相关标签:
1条回答
  • 2020-12-18 09:19

    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)

    0 讨论(0)
提交回复
热议问题