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