【发布时间】:2016-03-27 04:54:15
【问题描述】:
我需要在其他工作中使用<p:poll />。所以我尝试了 PrimeFaces ShowCase 代码:-
<!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>
而backing 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 一次,然后什么也没有。
这里有什么问题?我在 JSF 2.1 上使用 PrimeFaces 3.4.2
【问题讨论】:
-
应该可以,我唯一会尝试的是删除
listener属性中的(),例如#{counterView.increment}而不是#{counterView.increment()} -
<p:poll process="@this" .../> -
下次请阅读正确 PF 版本的文档以查看支持的内容
-
您从哪个showcase 页面获得了该代码? XML 命名空间用于 PrimeFaces 2.x,它已经不存在多年了。我无法想象它仍然出现在他们的展示中。
标签: jsf primefaces