如何在primefaces中进行条件轮询?

时间:2017-04-26 13:44:49

标签: primefaces jsf-2

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

以下是投票代码:

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

例如,我是实地呼叫状态。如果状态值为“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>

2 个答案:

答案 0 :(得分:1)

模式1:
p:pollh:panelGroup中包裹您的h:panelGrid标记,并在面板上设置rendered="#{backingBean.status eq 'In-Progress'}"并更新状态组件更改的轮询容器(面板),这将重置您的轮询。< / p>

模式2:
如果你想手动启动&amp;停止投票,然后您需要在autoStart="false"上设置widgetVar="statusPoll"p:poll属性,并在更改状态字段值时调用PF('statusPoll').start();PF('statusPoll').stop();应该执行特技。

答案 1 :(得分:0)

它正在运作,

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

当我编写此面板时,Panel仅在status ='In-Progress'时显示,否则将不显示。

再次感谢你,