【问题标题】:How to do conditional polling in primefaces?如何在primefaces中进行条件轮询?
【发布时间】:2023-03-07 06:52:01
【问题描述】:

我想在 Primefaces(版本:6.0.0)中进行条件轮询。

这是投票代码:

<p:poll  interval="20" update="liveChart,chrtTC_Cnt_Status,chrtStatus" />

例如,我是外勤人员Status。如果状态值为“In-Progress”,则只应开始轮询。否则它不应该进行轮询。

这是我的字段代码,如果此值更改为“进行中”,则轮询应该开始,否则不

<p:outputLabel value="Status:" />
<p:outputLabel id="lblCurrentStatus" value="#{backingBean.status}" />

这是我的 Xhtml 代码

<h:panelGrid columns="2" width="400">

                    <p:outputLabel for="lblStudentName" value="Select Other StudentName: " />
                    <p:selectOneMenu id="lblStudentName" style="width:250px" 
                        value="#{backingBean.selectedStudent}"
                        panelStyle="width:180px" effect="fade" filter="true"
                        filterMatchMode="startsWith">
                        <f:selectItem itemLabel="Select One" itemValue=""
                            noSelectionOption="true" />
                        <f:selectItems value="#{backingBean.studentItemList}" />
                        <p:ajax
                            listener="#{backingBean.OnChangeOtherStudentDropDown}"
                            update=":idForm:tabStatus:p1,:idForm:tabStatus:p4,growl"
                            process="@form" />
                    </p:selectOneMenu>


                <p:tabView id="tabStatus">
            <p:tab title="Status" id="idStatusTab">
                <h:panelGrid columns="3" cellpadding="10" id="p1">
                    <p:growl id="growl" showDetail="true" />
                    <p:ajaxStatus onstart="PF('statusDialog').show()"
                        onsuccess="PF('statusDialog').hide()" />

                    <p:dialog widgetVar="statusDialog" draggable="false"
                        closable="false" resizable="false" showHeader="false">
                        <h:graphicImage value="/images/ajax-loader.gif" />
                    </p:dialog>
                    <h:panelGrid columns="2" cellpadding="5" id="p2">
                        <p:outputLabel value="Failed:" />
                        <p:outputLabel id="lblCurrentFailed"
                            value="#{backingBean.intCurrentFailedStudent}" />
                        <p:outputLabel value="Processed:" />
                        <p:outputLabel id="lblCurrentProcess"
                            value="#{backingBean.intCurrentPassedStudent}" />
                        <p:outputLabel value="Status:" />
                        <p:outputLabel id="lblCurrentStatus"
                            value="#{backingBean.status}" />

                    </h:panelGrid>
                    <h:panelGrid columns="2" cellpadding="10" id="p3">

                        <p:chart type="pie" model="#{backingBean.pieModel1}"
                            rendered="#{not empty backingBean.pieModel1}"
                            id="chrtStatus" style="width:300px;height:200px">
                        </p:chart>
                        <br />
                    </h:panelGrid>
                </h:panelGrid>


                <h:panelGrid columns="3" cellpadding="10" id="p4">

                <p:poll  interval="20" update="liveChart,chrtTC_Cnt_Status,chrtStatus" />
                    <p:chart type="line"
                        model="#{backingBean.lineCurrentLineChart}" 
                        rendered="#{not empty backingBean.lineCurrentLineChart}"
                        id="liveChart" style="height:500px;width:500px" />


                    <p:chart type="bar"
                        model="#{backingBean.barStatusCountStudent}"
                        rendered="#{not empty backingBean.barStatusCountStudent}"
                        id="chrtTC_Cnt_Status" style="width:500px;height:500px">
                         <p:ajax event="itemSelect" listener="#{backingBean.itemSelect}"  />
                    </p:chart>
                </h:panelGrid>
            </p:tab>

        </p:tabView>
</h:form>

【问题讨论】:

  • p:poll 标签包裹在h:panelGrouph:panelGrid 中,并在面板上设置rendered="#{backingBean.status eq 'In-Progress'}"
  • @ParkashKumar,它正在工作,但现在我观察到如果状态为“进行中”则轮询开始,但我想在状态更改为“失败”时停止。然而,轮询并没有停止。当我按 F5 时它停止。有什么想法吗?
  • 您的状态从哪个组件发生变化?您可以在更改该组件时更新投票面板,这将重置您的投票。
  • 或者其他方法是在p:poll上设置autoStart="false"widgetVar="statusPoll",然后您可以通过调用PF('statusPoll').start();PF('statusPoll').stop();来手动启动/停止更改状态字段的值.

标签: primefaces jsf-2


【解决方案1】:

解决方案 1:
将您的p:poll 包裹在h:panelGrouph:panelGrid 中,在面板上设置rendered="#{backingBean.status eq 'In-Progress'}" 并更新面板以更改状态,这将重置您的投票。

解决方案 2:
如果要手动启动和停止轮询,则需要设置autoStart="false" 并在p:poll 上添加widgetVar="statusPoll" 属性,并在更改状态字段的值时调用PF('statusPoll').start();PF('statusPoll').stop();

【讨论】:

  • 当我完成提及代码时,轮询开始像第一次轮询,第二轮轮询 2 次,第三轮轮询 3 次。继续。下面是代码。 &lt;p:tab title="Status" id="idStatusTab"&gt; &lt;h:panelGrid id="p1"&gt; &lt;/h:panelGrid&gt; &lt;h:panelGrid id="p4"&gt; &lt;h:panelGrid id="ID_polling" rendered="#{backingBean.status eq 'InProgress'}"&gt; &lt;p:poll interval="20" rendered="#{backingBean.status eq 'InProgress'}" update="tabStatus" async="false" /&gt; &lt;/h:panelGrid&gt; &lt;/h:panelGrid&gt; &lt;/p:tab&gt;
  • 我的意思是问,您的status 字段有什么更新?
  • Status 字段最初得到更新,正在进行中,然后失败或通过
【解决方案2】:

它正在工作,

<h:panelGrid columns="1" id="ID_polling" rendered="#{BackingBean.status eq 'In-Progress'}">    
          <p:poll  interval="20" update="liveChart,chrtTC_Cnt_Status,chrtStatus" />    
</h:panelGrid>

当我编写这个面板时,面板只会在 status = 'In-Progress' 时显示,否则它不会显示。

再次感谢您,

【讨论】:

  • 你为什么不直接接受@Parkash Kumar 的回答?
猜你喜欢
  • 2020-08-07
  • 1970-01-01
  • 2022-01-02
  • 2012-06-12
  • 1970-01-01
  • 1970-01-01
  • 2020-06-04
  • 2016-06-10
  • 1970-01-01
相关资源
最近更新 更多