PrimeFaces民意测验不起作用 [英] PrimeFaces poll does not work

查看:52
本文介绍了PrimeFaces民意测验不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在其他一些工作中使用<p:poll />.所以我尝试了PrimeFaces ShowCase代码:-

I need to use <p:poll /> in some other work. So I was trying out the PrimeFaces ShowCase code:-

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:p="http://primefaces.prime.com.tr/ui"
    xmlns:a4j="http://richfaces.org/a4j">
    <h:form>
    <h:outputText id="txt_count" value="#{counterView.number}" />
    <p:poll interval="3" listener="#{counterView.increment()}" update="txt_count" />
    </h:form>
</html>

支持bean如下:-

package com.poll;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

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

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private int number;

    public int getNumber() {
        return number;
    }

    public void increment() {
        number++;
        System.out.println(number);
    }
}

它是这样工作的:在浏览器中,number显示为0,并且没有变化.在控制台中,我可以看到它一次打印为1,然后什么也不打印.

It works as such: in browser number shows as 0 and doesn't change. In console I can see it printing as 1 once and then nothing.

这是怎么了?我在JSF 2.1上使用PrimeFaces 3.4.2

What is wrong here? I am using PrimeFaces 3.4.2 on JSF 2.1

推荐答案

p:poll标记对我有用,具有以下内容,并且我在Primefaces 5.2上.

The p:poll tag does work for me with the following content, and I am on Primefaces 5.2.

注意::<h:head/>标签是必需的,没有它,它会加载所需的与primefaces相关的js文件.我认为这是您的情况下刷新无法正常工作的原因.

NOTE: <h:head/> tag is needed and without that it does load primefaces related js files that are needed. I believe that is the reason why the refresh is not working in your case.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">

<h:head/>

<h:body>
        <h:form>
            <h:outputText id="txt_count" value="#{counterView.number}" />
            <p:poll interval="3" listener="#{counterView.increment}" update="txt_count" />
        </h:form>
</h:body>

</html>

和托管bean:

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

    private int number = 100;

    public int getNumber() {
        return number;
    }

    public void increment() {
        System.out.println("Incrementing....");
        number++;
    }
}

您可以尝试一下并比较是否可行.

Can you try with these and compare if it works.

更新:最终解决方案

要总结解决方案,请使用<h:head/>标记,如评论部分所述,升级到Primefaces的较新版本(5.x)可以解决此问题.

To summarize the solution, along the <h:head/> tag, upgrading to newer version (5.x) of Primefaces helped resolve the issue, as indicated in the comments section.

这篇关于PrimeFaces民意测验不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆