Я отключил <p:poll>
по умолчанию с autoStart="false"
.
Теперь у меня есть диалоговое окно, открытое commandButton с этим примером кода:
<h:body>
<h:form>
<p:commandButton value="Open Dialog" oncomplete="PF('sampleDialog').show();PF('w_poll').start();"/>
<p:dialog header="Sample Dialog" height="300" width="400" widgetVar="sampleDialog" resizable="false" onHide="PF('w_poll').stop();">
<p:accordionPanel>
<p:ajax event="tabChange" oncomplete="PF('w_poll').start();"/>
<p:tab title="First">
<h:panelGroup id="firstGroup">
<p:poll interval="1"
id="firstPoll"
widgetVar="w_poll"
update="firstLabel"
async="true"
autoStart="false"
global="false"
listener="#{firstCounter.init}"/>
<p:outputLabel value="#{firstCounter.number}" id="firstLabel"/>
</h:panelGroup>
</p:tab>
<p:tab title="Second">
<h:panelGroup id="secondGroup">
<p:poll interval="3"
id="secondPoll"
widgetVar="w_poll"
update="secondLabel"
async="true"
autoStart="false"
global="false"
listener="#{secondCounter.init}"/>
<p:outputLabel value="#{secondCounter.number}" id="secondLabel"/>
</h:panelGroup>
</p:tab>
<p:tab title="Third">
<h:panelGroup id="thirdGroup">
<p:poll interval="5"
id="thirdPoll"
widgetVar="w_poll"
update="thirdLabel"
async="true"
autoStart="false"
global="false"
listener="#{thirdCounter.init}"/>
<p:outputLabel value="#{thirdCounter.number}" id="thirdLabel"/>
</h:panelGroup>
</p:tab>
</p:accordionPanel>
</p:dialog>
</h:form>
</h:body>
Примечание: вы можетесм. опрос, запущенный в диалоговом окне и остановленный при скрытии.
это мои bean-компоненты:
public abstract class AbstractBean implements Serializable {
private int number;
public void counter(int sleepTime) {
sleep(sleepTime);
this.number = number + 1;
}
public int getNumber() {
return number;
}
private static void sleep(int time) {
try {
Thread.sleep(time);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
теперь реализуем три bean-компонента с этим резюме:
@Named
@ViewScoped
public class FirstCounter extends AbstractBean {
@PostConstruct
public void init() {
counter(1000);
}
}
и еще один:
@Named
@ViewScoped
public class SecondCounter extends AbstractBean {
@PostConstruct
public void init() {
counter(3000);
}
}
и еще:
@Named
@ViewScoped
public class ThirdCounter extends AbstractBean {
@PostConstruct
public void init() {
counter(5000);
}
}
У меня две проблемы:
1) первая вкладка панели аккордеона не запускается после открытия диалогового окна.
2) событие изменения вкладки неРабота .я хочу начать счетчик этой же вкладки.