Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

jsf - How to prevent PrimeFaces poll from clearing FacesMessages?

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>

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.

Is it possible to prevent poll from clearing FacesMessages without setting messages autoUpdate=false?

My web application is much bigger as code snippet specified above and my intention is not updating messages manually in each possible case!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...