PrimeFaces投票

I try to make a site where I place a clock. Not a default primefaces clock because I need the actual time not just to show it. I use Netbeans8.0, Java8.0, Primefaces5.0, and I'm building a Mobile site.

So I tried the p:poll but it not works for me.

@ViewScoped
@ManagedBean(name = "navigationTo")
public class NavigationTo implements Serializable{

    private int number;

    public int getNumber() {
        return number;
    }

    public void increment() {
        number++;
    }
}

<h:body>
        <pm:page id="index">
            <pm:header title="xyz"></pm:header>
            <pm:content>
                <h:form>
                    <p:growl id="growl" showDetail="true"/>
                    <h:outputText id="txt_count" value="#{navigationTo.number}" />
                    <p:poll interval="3" listener="#{navigationTo.increment}" update="txt_count" />
                    <p:graphicImage value="xyz.png" style="width: 30%;

I use this default primefaces example but only shows the 0 and it's not incrementing...

Anyone any idea?

!!!EDIT: Primefaces Mobile (here: pm) not support polling. So it only work with the basic primefaces.

well, I look your situation, I did a example about it, It work for me!

I have created a Bean similar to your bean.

    @ViewScoped
    @ManagedBean(name="clockBean")
   public class clockBean implements Serializable{

        private  int number;

        public void increment(){
           number++;
        }

        public int getNumber() {
          return number;
        }

        public void setNumber(int number) {
          this.number = number;
        }
}

Besides I created a simple web page

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui"
    xmlns:pe="http://primefaces.org/ui/extensions">
  <ui:composition template="/layout/template.xhtml">
  <ui:define name="body">
   <h:form id="form">
            <p:poll interval="1"
                listener="#{clockBean.increment}" update=":form" />
            <p:outputLabel value="#{clockBean.number}" />
    </h:form>
  </ui:define>
  </ui:composition> 

 </html>

It has worked for me, I hope it can help you!.

I think that your problem is that you need use id for the different components in your web page for exaMple the component form, it should has a id.

Adding

<h:outputScript library="primefaces" name="primefaces.js" />

inside h:body solved for me. I'm using PrimeFaces 5.1.20

For me, adding this line to <h:body> helped:

<h:outputScript library="primefaces/poll" name="poll.js" />

Have you debugged the actual navigationTo.increment method, and checked that the poll actually goes inside?

It seems that you are missing attributes inside the poll, if you want to trigger the back end method, and start the actual poll as soon as you load the page, add this:

process="@this" autoStart="true"