How to prevent PrimeFaces poll from clearing FacesMessages?

青春壹個敷衍的年華 提交于 2019-11-29 13:50:55

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.

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

(note: no additional bean properties needed)

PrimeFaces 4.x+

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

For folks using Primefaces 4.0 and above, the Primefaces team have added an attribute to their ajax aware components to skip triggering components with autoUpdate set to true. So your poll would be

<p:poll ignoreAutoUpdate="true" .../>

See also their blog post about it: http://blog.primefaces.org/?p=2836

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!