本文介绍了JSF使用EL来测试全局消息的存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
仅当JSF队列中有Global消息时,我才尝试显示一个块.
I'm trying to display a block only if there are Global messages in the JSF Queue.
我尝试使用rendered="#{not empty facesContext.getMessageList(null)}"
,但始终将其评估为false.
I tried to use rendered="#{not empty facesContext.getMessageList(null)}"
, but it's always evaluated to false.
我发现的唯一方法是创建一个自定义的EL函数并在Java中对其进行测试.
Only way I found is to create a custom EL function and test it in java.
例如:我的el函数:
eg. :my el function :
public static boolean isFacesGlobalMessages() {
return ! FacesContext.getCurrentInstance().getMessageList(null).isEmpty();
}
JSF页面:
<h:panelGroup class="block1" layout="block" rendered="#{el:isFacesGlobalMessages()}">
<div class="block-warn-body">
<rich:messages id="msg" globalOnly="true"/>
</div>
</h:panelGroup>
我正在使用Mojarra 2.1.5.
I'm using Mojarra 2.1.5.
我想念什么吗?谢谢!
Am I missing something ?Thanks !
尝试了以下建议,但到目前为止还没有运气:
Edit : tried the following suggestions, but no luck so far :
-
#{not empty facesContext.getMessageList(null)}
->始终为假 -
#{! facesContext.getMessageList(null)}
->错误 -
#{! empty facesContext.getMessageList(null)}
->始终为假 -
#{fn:length(facesContext.getMessageList(null)) > 0}
->始终为假 -
#{not empty facesContext.messageList(null)}
->错误:找不到方法messageList -
#{not empty facesContext.messageList}
->如果它是验证错误,则返回true(我只希望在全局错误时为true) -
#{! facesContext.getMessageList(null).isEmpty()}
->抛出IllegalAccessException:类javax.el.BeanELResolver无法访问带有修饰符"public"的类java.util.Collections $ UnmodifiableCollection的成员
#{not empty facesContext.getMessageList(null)}
-> always false#{! facesContext.getMessageList(null)}
-> error#{! empty facesContext.getMessageList(null)}
-> always false#{fn:length(facesContext.getMessageList(null)) > 0}
-> always false#{not empty facesContext.messageList(null)}
-> Error : Method messageList not found#{not empty facesContext.messageList}
-> returns true if it's a validation error (I only want true on global error)#{! facesContext.getMessageList(null).isEmpty()}
-> throws IllegalAccessException: Class javax.el.BeanELResolver can not access a member of class java.util.Collections$UnmodifiableCollection with modifiers "public"
推荐答案
不需要自定义EL函数
尝试
rendered="#{not empty facesContext.messageList}"
编辑
我自己还没有尝试过,但是请尝试
Haven't tried it myself , but try
rendered="#{not empty facesContext.messageList(null)}"
一个主意...
rendered="#{not facesContext.validationFailed and not empty facesContext.messageList}"
这篇关于JSF使用EL来测试全局消息的存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!