2014-06-12 106 views
0

我试图做一个网站,我放置一个时钟。不是默认的primefaces时钟,因为我需要的实际时间不仅仅是为了显示它。我使用Netbeans8.0,Java8.0,Primefaces5.0,并且正在构建移动网站。PrimeFaces民意调查

所以我试了p:民意调查,但它不适合我。

@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%; 

我用这个默认primefaces的例子,但只显示为0而不是递增......

任何人任何想法?

!!!编辑:Primefaces Mobile(here:pm)不支持轮询。所以它只适用于基本的素数。

+0

你试过来自PrimeFaces展示的简单例子? http://www.primefaces.org/showcase/ui/ajax/poll.xhtml您也可以在浏览器的JavaScript控制台中查看任何错误。最后,我会在侦听器方法中设置一个断点或println,以查看它是否被正确触发。 – QueryLars

回答

0

好吧,我看你的情况,我做了一个例子,它适合我!

我创建了一个类似于你的bean的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; 
     } 
} 

此外,我创建了一个简单的网页

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

它已经为我工作,我希望它可以帮助你!

我认为你的问题是,你需要使用ID为你的网页中的不同组件,例如组件形式,它应该有一个ID。

+0

对不起,我解决了这个问题。问题是Primefaces Mobile不支持轮询。顺便说一句,你的答案正在工作,因为它必须。 – Guigreg

0

添加

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

^h内:身体解决了我。我使用PrimeFaces 5.1.20

0

对于我来说,加入这行来<h:body>帮助:

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

你调试的实际navigationTo.increment方法,并检查了民意调查居然走了进去?

看来你是民意调查中缺少的属性,如果你想尽快加载页面触发后端方法,并开始实际调查,补充一点:

process="@this" autoStart="true"