如何防止 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 的情况下阻止轮询清除 FacesMessage?
我的网络应用程序比上面指定的代码片段大得多,我的目的不是在每种可能的情况下手动更新消息!
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
这在本地是不可能的,所以需要一个技巧.在
的rendered
属性中,检查
是否被触发,如果是,则返回假
.这样 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.
如果
被触发,则其客户端 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
以忽略所有 autoUpdate=true"
组件ajax 更新.
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屋!