0

I am facing unexpected p:poll behaviour

.xhtml page

<h:form>
    <h:panelGrid columns="2">
        <p:commandButton actionListener="#{homeBean.start}" onclick="start();"
            disabled="#{homeBean.hasStarted}" value="Start" process="@form"
            update="@form" styleClass="sendBtn">
        </p:commandButton>
        <p:commandButton actionListener="#{homeBean.stop}" value="Stop" oncomplete="stop();"
            async="true" process="@form" update="@form">
        </p:commandButton>
    </h:panelGrid>

    <p:poll interval="1" listener="#{homeBean.fetchUpdates}" autoStart="false" async="true" update="@form" widgetVar="poll" />
<h:form>

JS code

$( document ).ready(function() {
    stop(); // If there is already any polling then stop. Just for safe side. But PF('poll') is always *undefined* at start
});

function start() {
    if(PF('poll') && !PF('poll').isActive()){
        PF('poll').start();
    }
}

function stop() {
    if(PF('poll') && PF('poll').isActive()){
        PF('poll').stop();
    }
}

So if I click on start, polling starts, and on clicking stop button, polling stops (This works fine.).

But say if I click on start, (polling starts), after that if server is stopped (manually or due to exception) before clicking on stop button, then I restart the server then the polling continues even before page loading. Also PF('poll') returns undefined on page load. It looks like that server is not removing the poll instance. (I also try to restart the server after clearing all the resources from the server but no luck)

Note: HomeBean#start() has a never ending loop which stop only if I click on stop button.

As polling starts even before the page is loaded so it gives following exception again and again

May 19, 2017 12:54:37 PM com.sun.faces.context.AjaxExceptionHandlerImpl handlePartialResponseError
SEVERE: javax.faces.application.ViewExpiredException: viewId:/index.xhtml - View /index.xhtml could not be restored.
    at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:212)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:123)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at com.webcrawler.filter.RequestLoggingFilter.doFilter(RequestLoggingFilter.java:26)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:509)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1104)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

May 19, 2017 12:54:37 PM com.sun.faces.context.AjaxExceptionHandlerImpl handlePartialResponseError
SEVERE: javax.faces.application.ViewExpiredException: viewId:/index.xhtml - View /index.xhtml could not be restored.
    at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:212)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:123)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at com.webcrawler.filter.RequestLoggingFilter.doFilter(RequestLoggingFilter.java:26)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:509)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1104)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

I am using primefaces 5.3, mojarra 2.2.12 and tomcat 8.0.

Junaid
  • 2,572
  • 6
  • 41
  • 77
  • Possible such behavior appeared because poll continue sending ajax to server even if the server is down. After server back to production it detected incoming ajax requests, but it can't restore view with that component because of previous downtime. What is the question - how to workaround it and reset poll after server startup? – Sergey Prokofiev May 19 '17 at 10:00
  • So how reset poll after server startup? Like server should not listen to old poll requests. Is there any way to do so ? – Junaid May 19 '17 at 10:01
  • @SergeyProkofiev don't you think that its a primefaces bug ? Like if server is stopped for maintenance then it is restarted. So the problem will be that unregistered clients/polls still sending the wrong requests to the server again and again. I think primefaces should assign unique ids to server and client sides' poll-instances so that if such case occurs then server and client stop communication rather keep the server busy ! – Junaid May 19 '17 at 10:26
  • 1
    Don't think that is bug. Regarding possible solution / workaround: you can use `onerror` method of p:poll to reset your poll instance, but that will not save you from ViewExpiredException. To overcome that problem you can set `javax.faces.STATE_SAVING_METHOD` to `client` to store your view on the client side (don't forget to check if your beans are serializable). [There is](http://stackoverflow.com/questions/3642919/javax-faces-application-viewexpiredexception-view-could-not-be-restored) a very good post about it. – Sergey Prokofiev May 19 '17 at 10:40
  • create and use an ajax exceptionhandler – Kukeltje May 19 '17 at 13:02

0 Answers0