如何防止PrimeFaces民意调查清除FacesMessages? [英] How to prevent PrimeFaces poll from clearing FacesMessages?
问题描述
我正在使用PrimeFaces民意调查组件刷新一些内容.
I'm using PrimeFaces poll component to refresh some content.
<h:form id="formBsvtt">
<p:messages autoUpdate="true" showDetail="false" />
<p:outputPanel id="panelOut" layout="block">
...
... content to refresh
...
</p:outputPanel>
<p:panelGrid id="panelIn" layout="block">
...
... various input components with validation
...
</p:panelGrid>
<p:poll widgetVar="poll1" autoStart="true" global="false" interval="15"
partialSubmit="true" process="@this" update="panelOut"
listener="#{myBean.myListener}">
</p:poll>
</h:form>
如您所见,我正在使用具有autoUpdate = true的消息.我的问题是:在验证错误的情况下,将显示FacesMessages,但不迟于15秒消失.
As you can see I'm using messages with autoUpdate=true. My Problem is: In case of validation errors FacesMessages will be shown, but disappear not later than 15 seconds.
是否可以在不设置消息autoUpdate = false的情况下防止民意调查清除FacesMessages?
Is it possible to prevent poll from clearing FacesMessages without setting messages autoUpdate=false?
我的Web应用程序比上面指定的代码段大得多,我的目的不是在每种可能的情况下手动更新消息!
My web application is much bigger as code snippet specified above and my intention is not updating messages manually in each possible case!
推荐答案
PrimeFaces 2.x/3.x
这在本地是不可能的,因此需要技巧.在<p:messages>
的rendered
属性中,检查是否触发了<p:poll>
,如果已触发,则返回false
.这样,JSF认为在呈现期间组件树中没有自动更新的消息组件,因此将其忽略.
PrimeFaces 2.x/3.x
This is not natively possible, so a trick is needed. In the rendered
attribute of <p:messages>
, check if <p:poll>
was been triggered and if so, then return false
. This way JSF thinks there's no auto-updatable messages component in the component tree during rendering and will therefore ignore it.
如果触发了<p:poll>
,则其客户端ID将显示为javax.faces.source
请求参数.因此,应该这样做:
If the <p:poll>
is triggered, then its client ID appears as javax.faces.source
request parameter. So, this should do:
<p:messages ... rendered="#{param['javax.faces.source'] ne poll.clientId}" />
...
<p:poll binding="#{poll}" ... />
(注意:不需要其他bean属性)
所有PrimeFaces命令组件都有一个新的ignoreAutoUpdate
属性,您可以将其设置为false
,以忽略ajax更新中的所有autoUpdate="true"
组件.
All PrimeFaces command components got a new ignoreAutoUpdate
attribute which you could set to false
to ignore all autoUpdate="true"
components in the ajax update.
<p:poll ... ignoreAutoUpdate="true" />
这篇关于如何防止PrimeFaces民意调查清除FacesMessages?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!