检入JSF EL,显示什么严重性消息 [英] Check in JSF EL what severity messages are shown

查看:78
本文介绍了检入JSF EL,显示什么严重性消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道使用EL在当前页面中显示哪种消息.我对超出警告严重性的错误特别感兴趣. 我当前的解决方案是这样:

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}

问题是我无法从facesMessage.SEVERITY_WARN中获得任何价值.有人可以帮我弄这个吗?谢谢.

The problem is that i can't get any value out of facesMessage.SEVERITY_WARN. Can someone help me with this? Thanks.

推荐答案

直到即将发布的 EL 3.0 ,您不能在EL中引用常量.

Until the upcoming EL 3.0, you can't reference constants in EL.

关于开源库,唯一可以帮助您解决此问题的是 OmniFaces .为此,它提供了 <o:importConstants> 标签.

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" />

这样您就可以使用

#{facesContext.maximumSeverity eq FacesMessage.SEVERITY_ERROR or facesContext.maximumSeverity eq FacesMessage.SEVERITY_FATAL}

#{facesContext.maximumSeverity.compareTo(FacesMessage.SEVERITY_WARN) gt 0}

#{facesContext.maximumSeverity.compareTo(FacesMessage.SEVERITY_ERROR) ge 0}

#{facesContext.maximumSeverity.ordinal gt FacesMessage.SEVERITY_WARN.ordinal}

#{facesContext.maximumSeverity.ordinal ge FacesMessage.SEVERITY_ERROR.ordinal}

(请注意,我省略了不必要的get前缀和()括号,EL中的IDE自动完成功能不一定会生成正确的代码)

(note that I omitted the unnecessary get prefix and () parens, IDE-autocomplete in EL doesn't necessarily generate right and clean code)

这篇关于检入JSF EL,显示什么严重性消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆