weixin_33744141 2014-06-12 14:54 采纳率: 0%
浏览 50

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.

  • 写回答

4条回答 默认 最新

  • weixin_33671935 2014-08-28 16:06
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 onlyoffice编辑完后立即下载,下载的不是最新编辑的文档
  • ¥15 求caverdock使用教程
  • ¥15 Coze智能助手搭建过程中的问题请教
  • ¥15 12864只亮屏 不显示汉字
  • ¥20 三极管1000倍放大电路
  • ¥15 vscode报错如何解决
  • ¥15 前端vue CryptoJS Aes CBC加密后端java解密
  • ¥15 python随机森林对两个excel表格读取,shap报错
  • ¥15 基于STM32心率血氧监测(OLED显示)相关代码运行成功后烧录成功OLED显示屏不显示的原因是什么
  • ¥100 X轴为分离变量(因子变量),如何控制X轴每个分类变量的长度。