How to prevent PrimeFaces polling from cleaning FacesMessages?

I am using PrimeFaces polling component to update 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 use messages with autoUpdate = true. My problem: in case of validation errors, FacesMessages will be displayed, but disappears no later than 15 seconds.

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

My web application is much larger than the above, and my intention is not to update messages manually in every possible case!

+6
source share
2 answers

PrimeFaces 2.x / 3.x

This is not possible initially, so a trick is needed. In the rendered <p:messages> attribute, check if <p:poll> was run, and if so, return false . Thus, the JSF does not consider that the component tree does not have a component of automatically updated messages during rendering, so it will ignore it.

If <p:poll> fires, its client identifier is displayed as the 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 are required)

PrimeFaces 4.x +

All components of the PrimeFaces team received a new ignoreAutoUpdate attribute, which you could set to false to ignore all autoUpdate="true" components in the ajax update.

 <p:poll ... ignoreAutoUpdate="true" /> 
+12
source

For users using Primefaces 4.0 and above, the Primefaces team has added an attribute to their ajax-enabled components to skip starting components with autoUpdate set to true. So your survey will be

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

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

+9
source

Source: https://habr.com/ru/post/948066/


All Articles